permaculture playing cards*
The moose likes Object Relational Mapping and the fly likes Hibernate Criteria object - how to... ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Criteria object - how to... ?" Watch "Hibernate Criteria object - how to... ?" New topic
Author

Hibernate Criteria object - how to... ?

Somak Dalui
Ranch Hand

Joined: Apr 19, 2005
Posts: 40
I have to execute a query like : Select * from Application a where a.appNum in (select appNum from Deal d where d.appNum = a.appNum); I tried this :

criteria.list() gives an error com.sybase.jdbc2.jdbc.SybSQLException: Incorrect syntax near ','.. The hibernate query generated is
select this_.appNum as y0_ from Application this_ where this_.appNum in (select this0__.appNum as y0_ from Deal this0__)
. I am using Sybase DB and Hibernate 3. Please help..
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

So why are you using a DetachedCriteria object in this case?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Somak Dalui
Ranch Hand

Joined: Apr 19, 2005
Posts: 40
oh ! ok So what am I missing here ? To fire a subquery what can I do instead of DetachedQuery ?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

add a Criteria object to the Criteria object. A Detached is for creating an object outside of a Session, and later on setting the session on the detached object, then executing the detached criteria.

Mark
Halcon Guatemala
Ranch Hand

Joined: Sep 06, 2006
Posts: 57
Hi to @ll, Mark, could you illustrate it? Could We nest distinct queries attaching criterias repeteadly?

Thanks in advance


"La verdadera sabidur´┐Ża viene del temor de Dios"
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Sort of, it is more subqueries that you are adding to the main query in the Criteria object. You can do a search at hibernate's web site to see more

http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#querycriteria

Mark
Somak Dalui
Ranch Hand

Joined: Apr 19, 2005
Posts: 40
Thank you Mark.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Criteria object - how to... ?
 
Similar Threads
inner query in hibernate
ClassCastException Hibernate
org.hibernate.exception.SQLGrammarException: could not execute query
Problem with Hibernate Criteria, Projections and associations
AND/OR in Hibernate - Criteria object