-->
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.  [ 3 posts ] 
Author Message
 Post subject: User/Role tables with Annotations
PostPosted: Mon May 05, 2008 4:54 pm 
Newbie

Joined: Tue Apr 29, 2008 7:01 pm
Posts: 4
Hi guys, I have the following three tables:

User (id, username)
Role (id, name, description)
User_Role (id, user_id, role_id)

In my user entity bean I have the following relationship:

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name="user_role",
joinColumns = @JoinColumn( name="user_id"),
inverseJoinColumns = @JoinColumn( name="role_id"))
public Set<Role > getRole() {
return role;
}


It all worked great until I had the need to have multiple roles per user. Now everytime I do a loadAll(User.class) and my user has two roles, hibernate returns two identical User objects. Am I doing something wrong? Is this the proper functionaility? If it is, how can I have hibernate return just one row per user?

Note: I also tried @ManyToMany without any luck...

Please heeeeeeeeeeelp :)

Thanks,
Julian.


Top
 Profile  
 
 Post subject: Re: User/Role tables with Annotations
PostPosted: Mon May 05, 2008 5:29 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
fetch = FetchType.LAZY will probably solve your problem.




Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 12:04 am 
Newbie

Joined: Tue Apr 29, 2008 7:01 pm
Posts: 4
Hi farzad, yes it does work for lazy loading, but I do need it to be eager. The roles need to be available as the user gets loaded (by acegi and other requirements).

Is there any other way around this?

Thanks.


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