[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5419?page=c...
]
Oliver Gierke edited comment on HHH-5419 at 9/5/11 1:07 AM:
------------------------------------------------------------
The interesting part about is that a) the problem also exists for the use of JPQL, but can
be worked around by using {{count(*)}} in that case. So it seems that {{count(*)}} is
translated differently into SQL that a {{count(x)}}. Is there a reason to treat both
approaches differently?
Reading up the other tickets it seems the problem is not only related to a single dialect
but (almost) all available. Here's the complete list (derived from the other
tickets):
* Oracle
* MySQL
* HSQL
* MSSQL
was (Author: oliver.gierke):
The interesting part about is that a) the problem also exists for the use of JPQL, but
can be worked around by using {{count(*)}} in that case. So it seems that {{count(*)}} is
translated differently into SQL that a {{count(x)}}. Is there a reason to treat both
approaches differently?
COUNT operator with composite primary key and JPA 2.0 Criteria API
produces bad sql
-----------------------------------------------------------------------------------
Key: HHH-5419
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5419
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.5.4, 3.6.0.Beta1
Environment: hibernate-entitymanager 3.6.0.Beta1, glassfish 3.0.1, linux ubuntu
10.04, MS SQL Server 2008
Reporter: Fabio Braga de Oliveira
Assignee: John Verhaeg
Priority: Minor
Fix For: 4.0.0.next
Attachments: hibernate-count-bug.zip
Hibernate produces a invalid SQL if anyone use the count() operator with the JPA 2.0
Criteria API. Code:
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<EntityCompositePK> r = cq.from(EntityCompositePK.class);
cq.multiselect(cb.count(r));
assertEquals(0, ((Long)
(getEntityManager().createQuery(cq).getSingleResult())[0]).intValue());
I'm sending a little maven project which reproduces the bug.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira