-->
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.  [ 5 posts ] 
Author Message
 Post subject: many to many Question
PostPosted: Fri Nov 03, 2006 3:37 pm 
Beginner
Beginner

Joined: Fri Nov 03, 2006 3:21 pm
Posts: 30
POJOs:

User.java
- idUser
- username
- password
- email

UserGroup (table, it is not mapped)
- idUser
- idGroup

Group.java
- idGroup
- name


CODE (INSERT):
...
user.setUsername("test");
Set<Group> listGroup = new HashSet<Group>();
listGroup.add(group);
user.setGroups(listGroup);


QUESTION:
In insert, when save a new User the Hibernate save data in table UserGroup for me.

But, as I do for alter the email of the User without have that load data of the UserGroup?

When I alter the User, the Hibernate is delete my data of the UserGroup (for this user).

Thanks


Top
 Profile  
 
 Post subject: hbm?
PostPosted: Mon Nov 06, 2006 2:45 am 
Beginner
Beginner

Joined: Mon Nov 06, 2006 2:40 am
Posts: 29
Location: New Delhi, India
Please attach your hbm files..


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 7:27 am 
Beginner
Beginner

Joined: Fri Nov 03, 2006 3:21 pm
Posts: 30
No hbm...
Annotations:

User.java:
Code:
   @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
   @JoinTable(name = "USER_GROUP", joinColumns = { @JoinColumn(name = "ID_USER") }, inverseJoinColumns = { @JoinColumn(name = "ID_GROUP") })
   public Set<Group> getGroups() {
      return this.groups;
   }


Group.java:
Code:
   @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "groups")
   public Set<User> getUser() {
      return this.users;
   }


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 7:46 am 
Beginner
Beginner

Joined: Mon Nov 06, 2006 2:40 am
Posts: 29
Location: New Delhi, India
Set cascade = none in both and remove inverseJoinColumn and try....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 8:20 am 
Beginner
Beginner

Joined: Fri Nov 03, 2006 3:21 pm
Posts: 30
If I remove the inverseJoinColumn gives problem in the my queries, because I need that the tables be related.

cascade = none

Remove the cascade did not resolve :/


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