2

For a Spring Boot project that used to work well with Hibernate 5, I try to upgrade Hibernate to version 6.

Now, when I run a @Query statement that uses an enumeration, I get this weird error:

java.lang.NullPointerException: 
Cannot invoke "org.hibernate.metamodel.mapping.JdbcMapping.getJdbcValueBinder()" 
because "jdbcMapping" is null

The error above happens only when I try to compare enums, for other basic types Hibernate works as expected.

The query is something like:

@Query("from SomeEntity r "+
     + "where r.enum_field = :#{#criteria.enum_field})")
Page<SomeEntity> search(@Param("criteria") TheCriteria criteria, Pageable pageable)

The entities look like this:

@Entity
@Table(name = "...")
@Getter
@Setter
public class SomeEntity { 
    ...   
    @Column(name = "ENUM_FIELD")
    @Enumerated(EnumType.STRING)
    private TheEnumType enum_field;
    ...
}

Criteria looks like this:

@Data
public class TheCriteria {   
    private TheEnumType enum_type;
}

Does anybody know what might be wrong?

user3429660
  • 2,420
  • 4
  • 25
  • 41
  • I had this same problem, but with using custom SQL used in `val query = entityManager.createNativeQuery(sql.toString())`, when setting variable like `query.setParameter("someEnumType", enumType.name)` the solution for me was to pass `enumType.name` instead of just `enumType`. – h3wro Jul 25 '23 at 16:27
  • This is the workaround I chose as well. Though, it's far from being elegant. – user3429660 Jul 26 '23 at 10:39
  • While searching for a solution for a very similar problem I stumbled upon this hibernate bug ticket https://hibernate.atlassian.net/browse/HHH-17006 . Maybe this is the same problem. In that case the bugfix will be included in Hibernate 6.3.0 – Cereaubra Aug 02 '23 at 13:23

0 Answers0