-->
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.  [ 2 posts ] 
Author Message
 Post subject: ManyToMany Refresh JoinedTable
PostPosted: Wed Sep 07, 2005 6:58 am 
Newbie

Joined: Sat Sep 03, 2005 9:17 am
Posts: 2
Hibernate version:3.1

Run code:
Code:
Session s =userDAO.openSession();
User user = userDAO.findByUserIdn(username, s);
.....
s.close();




class User {
...
      @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
   @JoinTable(table = @Table(name = "userspermissiongroups"), joinColumns = @JoinColumn(name = "userId"), inverseJoinColumns = @JoinColumn(name = "permissionsGroupId"))
   public java.util.Collection<PermissionsGroup> getPermissionsGroups() {
      if (permissionsGroups == null)
         permissionsGroups = new java.util.HashSet<PermissionsGroup>();
      return permissionsGroups;
   }

....
}


When i run this code
Hibernate always refresh tables:
userspermissionsgroup.
Hibernate try delete records in table userspermissionsgroup:
and next try to insert the same records to this table:
This is sql requests:
delete from userspermissiongroups where userId=?
insert into userspermissiongroups (userId, permissionsGroupId) values(?,?)

Why he do it?


Thanks Konrad?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 6:10 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
because it's a Collection, hence have a bag semantic, hence the collections elements can be duplicated and have no PK.

You probably need a Set

_________________
Emmanuel


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