aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate Count Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Count Query" Watch "Hibernate Count Query" New topic
Author

Hibernate Count Query

joy b chakravarty
Ranch Hand

Joined: May 16, 2011
Posts: 62



Here q1 and q2 don't behave the same (which is strange as its been interchangeably used in the hibernate reference document).

The query q1 works fine for tables where one has 'single column' primary key, but for tables having composite keys this breaks as follows:

Hibernate: select count((employee0_.NAME, employee0_.AGE)) as col_0_0_ from Employee employee0_ [Here 'Name' and 'Age' form the composite key for Employee]
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: java.sql.SQLException: ORA-00907: missing right parenthesis

Looks like for q1 it counts the primary key, which will definitely fail in case of composite key.

Hope this helps


Cheers, Joy [SCJP 1.4, SCBCD 5.0]
get high on alcohol, algorithm or both
Hemant Thard
Ranch Hand

Joined: Dec 23, 2008
Posts: 122
hi joy,

Thanks for sharing.
that was informative.

Regards,
Hemant
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Count Query
 
Similar Threads
Regarding time taken by query
Hibernate_listing database values
Problem finding objets with composite key
@Basic(fetch = FetchType.LAZY) does not work
ProjectionList hibernate Criteria