-->
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: (Solved) @OnyToMany entry inserted twice on Cascade.ALL
PostPosted: Thu Feb 21, 2008 3:55 pm 
Newbie

Joined: Tue Mar 15, 2005 7:37 am
Posts: 16
Hibernate version:
Hibernate EntityManager 3.2.1.GA
Hibernate Annotations 3.2.1.GA
Hibernate 3.2.3

Mapping documents:
one end:
Code:
   @OneToMany(mappedBy="contract", cascade=CascadeType.ALL)
   public List<ContractNote> getContractNotes() {
      return contractNotes;
   }
   public void setContractNotes(List<ContractNote> contractNotes) {
      this.contractNotes = contractNotes;
   }


and the other:
Code:
   @ManyToOne
   @JoinColumn(name = "CONTRACT_ID")
   public Contract getContract() {
      return contract;
   }
   public void setContract(Contract contract) {
      this.contract = contract;
   }


Code between sessionFactory.openSession() and session.close():

What I'm basically doing is trying to add a new ContractNote to an existing Contract:
Code:
Contract c = em.find(Contract.class, id);
ContractNote cn = new ContractNote();
cn.setContract(c);
c.addContractNote(cn);
em.flush();


What happens is that I end up with two ContractNotes in the database and I can see in the hibernate log that indeed hibernate issues two inserts.

Shouldn't this work or am I doing something completely wrong?

/Magnus


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 4:42 pm 
Newbie

Joined: Tue Mar 15, 2005 7:37 am
Posts: 16
I was being stupid and was merging() the entity into another entity manger where it was also being flushed. :X


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.