File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Help with Hibernate Criteria" Watch "Help with Hibernate Criteria" New topic

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

Retreive all users by application ID.


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

Is there any other efficient way?


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

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 = crit.createCriteria("user", "u");

But, it didn't do anything different.

Any other ideas?
I agree. Here's the link:
subject: Help with Hibernate Criteria
jQuery in Action, 3rd edition