[Hibernate-JIRA] Created: (HHH-7277) Problem with expressions in criteria CASE WHEN OTHERWISE
by Srini (JIRA)
Problem with expressions in criteria CASE WHEN OTHERWISE
---------------------------------------------------------
Key: HHH-7277
URL: https://hibernate.onjira.com/browse/HHH-7277
Project: Hibernate ORM
Issue Type: Bug
Components: query-criteria
Affects Versions: 4.1.2, 3.6.1
Environment: Windows 7, JRE 1.6, JPA 2.0, MySQL, SQL Server 10.50.1600.1
Reporter: Srini
JPA/Hibernate is not allowing to use an expression in WHEN and OTHERWISE clause of CASE statement. Following is criteria code, generated JPQL and the error it is throwing
Case<String> sectorCase = cb.selectCase();
sectorCase.when(cb.notEqual(sectors.get(Sectors_.sectorName), Constants.ACCOUNT_TYPE_RESIDENTIAL), root.get(Customers_.customerName)).
otherwise(cb.concat(root.get(Customers_.firstName), root.get(Customers_.lastName)));
List<Selection<?>> selectCols = new ArrayList<Selection<?>>();
selectCols.add(root.get(Customers_.id).alias("id"));
selectCols.add(sectorCase.alias("name"));
cq.multiselect(selectCols);
Error Details:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: expecting "end", found '||' near line 1, column 171 [select distinct generatedAlias0.id, case when sector.sectorName<>:param0 then generatedAlias0.customerName else generatedAlias0.firstName || generatedAlias0.lastName end from com.abc.persistence.entity.Customers as generatedAlias0 left join generatedAlias0.sectors as sector order by case when sector.sectorName<>:param2 then generatedAlias0.customerName else generatedAlias0.firstName || generatedAlias0.lastName end asc]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:79)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:276)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:180)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:119)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:215)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:193)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1649)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:488)
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 3 months
[Hibernate-JIRA] Commented: (HHH-567) Duplicate "Order By" clause generated when using native sql statement with paging enabled
by Mark Adelsberger (JIRA)
[ https://hibernate.onjira.com/browse/HHH-567?page=com.atlassian.jira.plugi... ]
Mark Adelsberger commented on HHH-567:
--------------------------------------
(And as I misinterpreted the forum's date format, the issue is even older than I thought. Maybe best to disregard; sorry)
> Duplicate "Order By" clause generated when using native sql statement with paging enabled
> -----------------------------------------------------------------------------------------
>
> Key: HHH-567
> URL: https://hibernate.onjira.com/browse/HHH-567
> Project: Hibernate ORM
> Issue Type: Bug
> Components: core
> Affects Versions: 3.0.3
> Environment: Hibernate 3.0.3, RDBMS: DB2/NT, version: 07.02.0000
> Reporter: steven
>
> When a native sql is issued as following:
> select person.oid as {personData.oid}, pn.firstName as {personData.firstName}, pn.lastName as {personData.lastName},person.dateOfBirth as {personData.birthDate}, person.gender as {personData.gender}, person.maritalStatus as {personData.maritalStatus}, pa.region as {personData.region}, pa.city as {personData.city}, pa.postalCode as {personData.zip} from Person person left outer join CPref2PostalAddress m on m.cprefId = person.defaultCPrefId left outer join PostalAddress pa on m.postalAddressId = pa.oid left outer join PersonName pn on pn.personId = person.oid where person.gender = :gender order by {personData.lastName} desc]
> the generated sql is:
> select * from ( select rownumber() over(order by lastName22_0_ desc) as rownumber_, person.oid as oid0_, pn.firstName as firstName22_0_, pn.lastName as lastName22_0_,person.dateOfBirth as birthDate22_0_, person.gender as gender22_0_, person.maritalStatus as maritalS7_22_0_, pa.region as region22_0_, pa.city as city22_0_, pa.postalCode as zip22_0_ from Person person left outer join CPref2PostalAddress m on m.cprefId = person.defaultCPrefId left outer join PostalAddress pa on m.contactPointId = pa.oid left outer join PersonName pn on pn.personId = person.oid order by lastName22_0_ desc ) as temp_ where rownumber_ <= ?
> but the db2 complains that the second "order by" is illegal.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 3 months
[Hibernate-JIRA] Commented: (HHH-567) Duplicate "Order By" clause generated when using native sql statement with paging enabled
by Mark Adelsberger (JIRA)
[ https://hibernate.onjira.com/browse/HHH-567?page=com.atlassian.jira.plugi... ]
Mark Adelsberger commented on HHH-567:
--------------------------------------
I realize this issue is a bit old, but maybe worth noting: prior to v9 DB2 really wouldn't let you put ORDER BY in a subselect. The issue is worded confusingly - it suggests that the appearance of ORDER BY at two paces in the query is the problem, but that is not the case. However, if your attempt to reproduce used a current version of DB2, then that's why you can't reproduce it; the query may "look" correct, but DB2 7 would reject it.
> Duplicate "Order By" clause generated when using native sql statement with paging enabled
> -----------------------------------------------------------------------------------------
>
> Key: HHH-567
> URL: https://hibernate.onjira.com/browse/HHH-567
> Project: Hibernate ORM
> Issue Type: Bug
> Components: core
> Affects Versions: 3.0.3
> Environment: Hibernate 3.0.3, RDBMS: DB2/NT, version: 07.02.0000
> Reporter: steven
>
> When a native sql is issued as following:
> select person.oid as {personData.oid}, pn.firstName as {personData.firstName}, pn.lastName as {personData.lastName},person.dateOfBirth as {personData.birthDate}, person.gender as {personData.gender}, person.maritalStatus as {personData.maritalStatus}, pa.region as {personData.region}, pa.city as {personData.city}, pa.postalCode as {personData.zip} from Person person left outer join CPref2PostalAddress m on m.cprefId = person.defaultCPrefId left outer join PostalAddress pa on m.postalAddressId = pa.oid left outer join PersonName pn on pn.personId = person.oid where person.gender = :gender order by {personData.lastName} desc]
> the generated sql is:
> select * from ( select rownumber() over(order by lastName22_0_ desc) as rownumber_, person.oid as oid0_, pn.firstName as firstName22_0_, pn.lastName as lastName22_0_,person.dateOfBirth as birthDate22_0_, person.gender as gender22_0_, person.maritalStatus as maritalS7_22_0_, pa.region as region22_0_, pa.city as city22_0_, pa.postalCode as zip22_0_ from Person person left outer join CPref2PostalAddress m on m.cprefId = person.defaultCPrefId left outer join PostalAddress pa on m.contactPointId = pa.oid left outer join PersonName pn on pn.personId = person.oid order by lastName22_0_ desc ) as temp_ where rownumber_ <= ?
> but the db2 complains that the second "order by" is illegal.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 3 months
[Hibernate-JIRA] Created: (HV-562) Incorrect use of TCL to check visibility to JPA classes
by Sanjeeb Sahoo (JIRA)
Incorrect use of TCL to check visibility to JPA classes
-------------------------------------------------------
Key: HV-562
URL: https://hibernate.onjira.com/browse/HV-562
Project: Hibernate Validator
Issue Type: Bug
Components: engine
Affects Versions: 4.1.0.Final
Reporter: Sanjeeb Sahoo
Priority: Critical
org.hibernate.validator.engine.resolver.DefaultTraversableResolver uses Thread's context class loader to check existence of PERSISTENCE_UTIL_CLASS_NAME as shown in the code below:
The following code
private void detectJPA() {
try {
loadClass( PERSISTENCE_UTIL_CLASS_NAME, this.getClass() );
log.debug( "Found {} on classpath.", PERSISTENCE_UTIL_CLASS_NAME );
}
loadClass() first tries to use TCL to load the class. If TCL can't load, then it uses the class loader of the second argument to load the class. This is incorrect. It does not matter whether TCL can load PERSISTENCE_UTIL_CLASS_NAME, what matters is whether the class loader which is going to be used to load JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME can load PERSISTENCE_UTIL_CLASS_NAME or not. Since HV-363 has now been fixed to use current class loader to load JPA_AWARE_TRAVERSABLE_RESOLVER_CLASS_NAME, the same class loader should also be used to detect existence of PERSISTENCE_UTIL_CLASS_NAME.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 3 months
[Hibernate-JIRA] Created: (JPA-31) Simple JPQL with guarded null Parameter fails with Postgresql
by Bernard (JIRA)
Simple JPQL with guarded null Parameter fails with Postgresql
-------------------------------------------------------------
Key: JPA-31
URL: https://hibernate.onjira.com/browse/JPA-31
Project: Java Persistence API
Issue Type: Bug
Affects Versions: 1.0.0
Environment: HIbernate 4.1.1 final, Postgresql driver 9.1-901-1.jdbc4
Reporter: Bernard
Priority: Critical
Attachments: NullParameterHibernatePostgresMaven.zip
The attached tests contain a case that is similar to
http://en.wikipedia.org/wiki/Java_Persistence_Query_Language#Examples
that shows a JPQL query as follows:
like SELECT a FROM Author a WHERE :lastName IS NULL OR LOWER(a.lastName) =
:lastName
Hibernate crashes in cases where the parameter values are null:
ERROR: operator does not exist: character varying = bytea
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
The message originating from the engine or driver are not helpful because JPQL does not support type casts.
I think the times are over where on application level one had to code different queries depending on whether a parameter value was null or not.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 3 months