Search code examples
javaspring-boothibernatespring-datahibernate-6.x

Migrating to Hibernate 6 @Type annotation not working for boolean


I upgraded spring boot to 3.x which in turn upgrades Hibernate from 5 to 6 and spring 6.

In previous versions we were using @Type annotation which converts db column from String (Y or N) to java boolean value.

    @Column(name = "IS_SPECIAL")
    @Type(type = "yes_no")
    private Boolean isSpecial;

The problem I am now facing is that there's a syntax error that reads:

Cannot resolve method 'type'

The annotation doesn't accept a string value either.

I have already checked this question and it's not helping.


Solution

  • Taking the answer from here

    @Type(type = "yes_no") can be replaced with @Convert(converter = YesNoConverter.class)

    @Column(name = "IS_SPECIAL")
    @Convert(converter = org.hibernate.type.YesNoConverter.class)
    private Boolean isSpecial;