You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I have a complex JPASQLQuery where I have to pass some localdate (joda) and enum for comparison.
There is the interesting parts (dateLimit is org.joda.time.LocalDate):
.where(qTable1.date.loe(dateLimit))
when I look in the mysql general log this part of the query is transformed as follow :
where table1.Date <= '��\0sr\0org.joda.time.LocalDate�������\0J\0 iLocalMillisL\0 iChronologyt\0\ZLorg/joda/time/Chronology;xp\0\0[��x\0sr\0\'org.joda.time.chrono.ISOChronology$Stub��fq7P\'\0\0xpsr\0org.joda.time.DateTimeZone$Stub�/�|2\Z�\0\0xpw\0UTCxx'
Same issue with enum :
.and(qTable1.type.ne(Type.R))
in the mysql general log :
and table1.BType != '��\0~r\0#enums.Type\0\0\0\0\0\0\0\0\0\0xr\0java.lang.Enum\0\0\0\0\0\0\0\0\0\0xpt\0R'
How can I solve that ?
I'am using queryDSL 3.7.4 and hibernate : 5.1.4.Final
Seeing this issue as well in version 4.3.1 when passing an enum. The column in the JPA entity is annotated using @Enumerated(EnumType.STRING). From my initial debugging, it seems like com.querydsl.jpa.sql.AbstractJPASQLQuery#createQuery(boolean) delegates to com.querydsl.jpa.impl.JPAUtil#setConstants to set the parameters for the query.
No conversion takes place, instead the values are directly passed to javax.persistence.Query#setParameter(int, java.lang.Object). Since the query is a native SQL query, Hibernate doesn't know what to use as the bind type and chooses org.hibernate.type.SerializableType, which results in the serialized representation of the enum instance, as opposed to the name or ordinal.
The workaround is to use the Enum#name() instead. I'm using the following to work with the generics:
public static <T extends Enum<T>> Expression<? super T> toNameConstant(T value) {
return constant(value.name());
}
...
entity.status.eq(toNameConstant(Status.SUCCESS));
An alternative might be to register the exact type that the enum should be serialized as in Hibernate.
Ideally, QueryDsl would leverage Hibernate and the JPA annotations to convert the parameter to the correct type based on the entity type - this is already what is done in com.querydsl.jpa.NativeSQLSerializer to serialize the correct table/columns names.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hello,
I have a complex JPASQLQuery where I have to pass some localdate (joda) and enum for comparison.
There is the interesting parts (dateLimit is org.joda.time.LocalDate):
.where(qTable1.date.loe(dateLimit))
when I look in the mysql general log this part of the query is transformed as follow :
where table1.Date <= '��\0sr\0org.joda.time.LocalDate�������\0J\0 iLocalMillisL\0 iChronologyt\0\ZLorg/joda/time/Chronology;xp\0\0[��x\0sr\0\'org.joda.time.chrono.ISOChronology$Stub��fq7P\'\0\0xpsr\0org.joda.time.DateTimeZone$Stub�/�|2\Z�\0\0xpw\0UTCxx'
Same issue with enum :
.and(qTable1.type.ne(Type.R))
in the mysql general log :
and table1.BType != '��\0~r\0#enums.Type\0\0\0\0\0\0\0\0\0\0xr\0java.lang.Enum\0\0\0\0\0\0\0\0\0\0xpt\0R'
How can I solve that ?
I'am using queryDSL 3.7.4 and hibernate : 5.1.4.Final
Thanks for your answers.
Mario
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: