• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with Hibernate Criteria

 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try changing the fetch mode.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic