Quarkus: Hibernate Bean Validation not working well in graphql when attrbitues are declared in primary constructor in Kotlin

Created on 13 Dec 2020  路  6Comments  路  Source: quarkusio/quarkus

Describe the bug
Primary constructor is a good feature in kotlin that helps to achieve builder pattern. But bean validator (@NotNull) and @JsonbDateFormat doesn't work in the primary constructor

Expected behavior
Annotations for bean validator and date format should work in the primary constructor as it works in class attributes.

Actual behavior
Annotations are not evaluated.

To Reproduce

@Entity
@Table(name = "tb_financial_commitment")
class FinancialCommitment(
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long? = null,

    @Column(name = "limit_date")
    @NotNull(message = "Limit date must be provided!")
    @JsonbDateFormat(value = "dd/MM/yyyy")
    var limitDate: LocalDateTime? = null,

    var value: Double? = null
)

Environment (please complete the following information):

  • Output of uname -a or ver: 1.10.3
  • Output of java -version: 15
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.10.3
  • Build tool (ie. output of mvnw --version or gradlew --version): maven 3.6.3

Additional context
If the property are declared as class property with lateinit it works properly.

arehibernate-orm arekotlin arepersistence kinquestion

All 6 comments

/cc @Sanne, @evanchooly, @gsmet

can you expand a little on "not working well?" I think i can probably see what you're talking about just looking at the example but I'd rather not assume in case i'm wrong. I'd hate to waste everyone's time.

they are ignored.

@andfs you probably should use @field or @get kotlin annotations use-site. https://kotlinlang.org/docs/reference/annotations.html#annotation-use-site-targets

This would be my advice, too. Have you had a chance to try it?

Sorry for taking so long and taking your time with this.
You were right. Using @field worked pretty well.
Thanks for your patience answering me :D

Was this page helpful?
0 / 5 - 0 ratings