1

Any have problem of annotation doesnt work in Kotlin?

@Column(unique=true, nullable = false)
@Size(min = 1, max = 50)
var name: String = "",

@Size(max = 100)
var description: String = ""

I can save into database with empty string and the unique constraint also not working via the annotation. Anyone have similar issue before ? Kindly advise :)

Kim
  • 980
  • 1
  • 15
  • 29

3 Answers3

1

When using Kotlin, you need to apply the constraint validators on the getter methods. This should work:

@Column(unique=true, nullable = false)
@get: Size(min = 1, max = 50)
var name: String = "",

@get: Size(max = 100)
var description: String = ""
W.K.S
  • 9,787
  • 15
  • 75
  • 122
0

I do not think your issue is with Kotlin exactly.

@Size and @Pattern annotation are not working in Spring MVC

It is possible that you have missed the org.hibernate:hibernate-validator package in your dependency, but without more information I cannot be certain.

Dummyc0m
  • 111
  • 6
0

You can change to

@field: Size(max = 100)
var description: String = ""
TaoBit
  • 852
  • 7
  • 10