org.hibernate.type.NumericBooleanType not converting value in JPASQLQuery

Viewed 270

In my model, I declare this NumericBooleanType attribute:

@Column(name = "ST_ATIVO", nullable = false)
@Type(type = "org.hibernate.type.NumericBooleanType")
private Boolean ativo;

Then, in antother class, I am trying to do the following query:

List<Long> test = this.sqlQueryFactory.query()
            .select(equipe.id)
            .from(equipe)
            .where(equipe.ativo.isTrue())
            .fetch();

However, I got this error:

org.hibernate.exception.SQLGrammarException: could not extract ResultSet

Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = boolean

Shoudn't a NumericBooleanType boolean attribute in the query be converted to int by hibernate?

1 Answers

It's unclear what query api do you use. Assuming that you use querydsl you can try to correct your query in this way:

JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager);
List<Long> test = queryFactory.query()
   .select(equipe.id)
   .from(equipe)
   .where(equipe.ativo.eq(true))
   .fetch();
Related