This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
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 Elasticsearch in Action this week in the Big Data 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Hibernate Count Query