Skip to content

Incorrect parameter values with Hibernate custom types. #1413

@kwon37xi

Description

@kwon37xi

We are using querydsl 3.x, and there lots of legacy columns in our JPA Entity mappings, because of this we had to use many hibernate custom types.

When there are

  • the same java type(like Boolean) but different custom types'(like yes_no, true_false) columns related conditions
  • and their parameter values are the same (like Boolean.TRUE)
  • and parameters' position number is the same in a query(like ?1),

Hibernate maps parameter values incorrectly.
This was reported already - #1168
Actually I think this is a bug of hibernate - https://hibernate.atlassian.net/browse/HHH-9871 .
But QueryDSL can work around this bug.

For exampe, when there are two or more boolean types(same java type) but they're custom types like the following(it doesn't matter that the colums are in the same entity or two or more entities),

@Type(type = "true_false")
@Column(name = "employee", columnDefinition = "char(1)")
 private Boolean employee;

@Type(type = "yes_no")
@Column(name = "male", columnDefinition = "char(1)")
private Boolean male;

@Column(name = "old")
private Boolean old;

And in a QueryDsl query has conditions with same java type and same value(Boolean.TRUE), QueryDsl generates JPQL like the follwing,

// employee == Booealn,TRUE, male == Boolean.TRUE, old == Boolean.FALSE
from User user where employee = ?1 and male = ?1 and old = ?2

QueryDSL maps same java type value into same positional parameter.

real parameter value mappings in hibernate is like the following

employee = 'T' and male = 'T' and old = false

male parameter must have been 'Y' but it follows the first parameter value - 'T'.

employee and male columns have same java type but different custom types, QueryDsl maps same positional parameter(?1) to these two columns.

I wonder QueryDSL could map different poisitional parameters for every different condition even though they have same java type value(like Boolean.TRUE in the example).

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions