-->
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: ManyToMany -> exception when delete
PostPosted: Sat Dec 09, 2006 5:51 pm 
Newbie

Joined: Thu Dec 07, 2006 6:02 pm
Posts: 4
I am working with JBOSS, SEAM und EBJ 3.0 and I am Hibernate Annotations.
I have a ManyToMany relationship between 2 beans and want to delete instances of both Beans. Here the code :
Bean1
Code:
@ManyToMany(targetEntity = User.class,fetch = FetchType.EAGER)
@JoinTable(name = "CFP_userprofile_contributable_map", joinColumns = @JoinColumn(name = "c_id"), inverseJoinColumns = @JoinColumn(name = "login"))
public Collection<User> getFavoriteUsers() {
      return favoriteUsers;
   }


Bean2
Code:
@ManyToMany(mappedBy = "favoriteUsers",targetEntity = Contributable.class, fetch = FetchType.EAGER)
public Collection<Contributable> getContributableFavorites() {
      if (contributableFavorites == null) {
         contributableFavorites = new ArrayList<Contributable>();
      }
      return contributableFavorites;
   }


When I delete an instance of bean1 with
Code:
entitymanager.remove(bean1);
this works, but when I try to delete an instance of bean2 I get this exception:
Code:
23:12:58,859 ERROR [JDBCExceptionReporter] Cannot delete or update a parent row: a foreign key constraint fails (`jbossdb/cfp_contributable`, CONSTRAINT `FKCE4305C0FFE09684` FOREIGN KEY (`creator_login`) REFERENCES `cfp_user` (`login`))
23:12:58,859 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update


How can I use the ManyToMany relationship and delete instances of both beans?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 09, 2006 8:24 pm 
Newbie

Joined: Sat Dec 09, 2006 8:14 pm
Posts: 4
Does adding Cascade help?

something like

@ManyToMany(targetEntity = User.class,fetch = FetchType.EAGER, cascade=CascadeType.ALL)

Dale


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 10, 2006 12:25 am 
Newbie

Joined: Sat Aug 26, 2006 4:47 am
Posts: 9
hi, which version of Hibernate Core, Annotation and EntityManager you are using ?! I got similar issue after upgraded Hibernate Core from 3.2.0.GA to 3.2.1.GA. (with HAN 3.2.0.GA and HEM 3.2.0.GA)

when I look at the SQL generated by Hibernate, I found that the record in join table is not deleted before removing the target record in child table.


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.