kotlinjpahibernate-6.x

Hibernate 6 - Can not invoke "Object.getClass()" because "value" is null


I had issue after moving to Hibernate 6.7 following update criteria query snippet was causing an exception in new SQM model.

criteriaQuery.set(root.get(MyEntity_.tag), null as Tag?)

was throwing an exception:

Can not invoke "Object.getClass()" because "value" is null


Solution

  • The fix is to use literal instead of null:

    criteriaQuery.set(root.get(MyEntity_.tag), criteriaBuilder.nullLiteral<Tag>(Tag::class.java))