Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Count Query

 
joy b chakravarty
Ranch Hand
Posts: 62
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Hemant Thard
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi joy,

Thanks for sharing.
that was informative.

Regards,
Hemant
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic