Skip to content

Automatically unwrap inline value classes at query compilation time #79

@QuinnB73

Description

@QuinnB73

When using an inline value class as a column type, Hibernate thinks that the type is the wrapper primitive, whereas Yawn thinks that the type is the value class. This leads to class cast exceptions when Hibernate tries to cast the value class to the primitive.

Yawn should recognize inline value class column types and apply special handling to unwrap their primitive at query compilation time

To reproduce the issue:

@JvmInline
value class InternationalStandardBookNumber(val isbn: String)

@Entity
@Table(name = "books")
@YawnEntity
class Book {
  // ...
  @Column
  lateinit var isbn: InternationalStandardBookNumber
}

session.createYawnCriteria(BookTable) { books ->
  addEq(isbn, InternationalStandardBookNumber("123"))
}.uniqueResult()

Note that it seems to specifically only happen for String value classes. At least, I cannot reproduce with an Int value class, which requires me to bind a converter, but I can with a String one, which doesn't require me to bind a converter and doesn't work even if I do bind one.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions