• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with Hibernate Criteria

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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


 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try changing the fetch mode.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic