-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Multi searching from multiple tables with different keys
PostPosted: Mon Jul 10, 2006 9:52 am 
Newbie

Joined: Mon Jul 10, 2006 9:14 am
Posts: 1
How to search based on different criteria from the given below tables and their relation ships?
is there any way to use Criteria API for searching in multiple tables/classes?

E.g.

Table AAA
id (Pk)
group_type_id (fk-CCC)
name
des

Table BBB
id (primary key)
p_id
com_id (fk-DDD)
gp_id (fk-DDD)
st_date
end_date

Table CCC
id (PK)
name
des

Table DDD
com_id (PK)
com_name
set_ref_id

Relation ship b/w tables

AAA - BBB - > one to many
BBB - DDD -> many to one
AAA - CCC -> many to one



[/img]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 5:15 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
You should precise your needs if you want to get a better answer.

With the criteria API, you have to create the criteria object defining a root class, this way :
Code:
Criteria crit = session.createCriteria(YourEntity.class);


Then, use the names of the properties in te YourEntity class to build your query. For example :
Code:
crit.setFetchMode("someCollection", FetchMode.JOIN);
would override the lazy-loading mode for the someCollection collection.

Code:
crit.createCriteria("role")
would create what is called a "subcriteria".

Then use the add() method with the criterion you want and your query should be ok :-).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.