wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Help with Hibernate Criteria Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Help with Hibernate Criteria" Watch "Help with Hibernate Criteria" New topic
Author

Help with Hibernate Criteria

Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532

Three tables:
User - contains user information
application - contains applications information
user2application - a bridge table between user and application. Composed of primary key or user, and primary key of application

Query:
Retreive all users by application ID.

SQL:


I created this criteria, but not efficient. Produces a select statement for every user.


Is there any other efficient way?

Thanks



SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Try changing the fetch mode.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
Paul Sturrock wrote:Try changing the fetch mode.


The fetch mode in the .hbm file is set to join

I added this line:

crit = getHbnSession().createCriteria(User2Application.class, "u2a");
crit.add(Restrictions.eq("u2a.application.applicationId", appId));
crit = crit.setProjection(Property.forName("user"));
crit.setFetchMode(FetchMode.JOIN);
crit = crit.createCriteria("user", "u");


But, it didn't do anything different.

Any other ideas?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with Hibernate Criteria
 
Similar Threads
[Torque] save() works, but where is the primary key?
@PrimaryKeyJoinColumns does not work
how to get num of rows in ResultSet
Hibernate HQL: Query to Criteria
OJB error