-->
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.  [ 4 posts ] 
Author Message
 Post subject: User-Role-Access fetch?
PostPosted: Thu Apr 28, 2005 7:30 am 
Newbie

Joined: Thu Apr 28, 2005 6:48 am
Posts: 12
Location: Finland
Hi,

I have three entities, User, Role and Access.
User has many-to-many association to Role.
Role has many-to-many association to Access.

I want to make query that fetches data from all three tables, but I don't want to set association property 'lazy' to false in mapping file, because I don't want fetch all information every time.

This code already fetches users with roles
Code:
Criteria crit = session.createCriteria( UserBean.class );
crit.add( Expression.eq("username", username) );
crit.setFetchMode( "roles", FetchMode.EAGER );
List users = crit.list();


How can I make it to fetch Access also?

Hibernate version:2.1


Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 7:50 am 
Newbie

Joined: Thu Apr 28, 2005 6:48 am
Posts: 12
Location: Finland
Here is some additional information to my question.

Java classes,

UserBean
private String username;
private Set roles;

RoleBean
private String name;
private Set access;

AccessBean
private String name;

And I need to fetch data from three tables and then give it to logic, logic doesn't know about Hibernate, so I cannot use lazy initialization.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 8:24 am 
Newbie

Joined: Thu Apr 28, 2005 6:48 am
Posts: 12
Location: Finland
Problem solved, I think...

Following clause does what I want:

from UserBean as user
left join fetch user.roles as role
left join fetch role.access


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 8:45 am 
Newbie

Joined: Thu Apr 28, 2005 6:48 am
Posts: 12
Location: Finland
Ups, problem not solved yet. Somehow I managed to get results like it worked, but it does not.

Hmm...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.