-->
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: Problem persisting collection items
PostPosted: Thu Sep 21, 2006 6:00 pm 
Newbie

Joined: Thu Sep 21, 2006 5:45 pm
Posts: 1
Hi, I'm using Hibernate Annotations 3.2.0.CR1 with Entity Manager 3.2.0.CR1.
I'm having a problem when I update (merge) a object with new added child itens. It seems that hibernate is calling merge for the child itens too put it should have called persist because the itens are new and are not persisted yet.
When I merge the object I get the following exception:

javax.persistence.EntityNotFoundException: org.hibernate.UnresolvableObjectException: No row with the given identifier exists: program.CustomerContact#0

And the hibernate does a sql update and not a insert for the new child item.

The code:

Code:

class Customer
{
   (.....)


  @OneToMany(mappedBy = "customer", cascade= { CascadeType.ALL } )
  @Cascade({org.hibernate.annotations.CascadeType.ALL,     org.hibernate.annotations.CascadeType.DELETE_ORPHAN} )
  @OnDelete(action = OnDeleteAction.CASCADE)
  public List<CustomerContact> getContacts()
  {
       if ( contacts == null ) {
      contacts = new ArrayList();
       }
       
       return contacts;
  }

  public void addContact(CustomerContact c)
  {
       c.setCustomer(this);
       this.contacts.add(c);
  }

}



The code that adds the child item:

Code:

Customer o=em.find(Customer.class,0);
   
CustomerContact cc = new CustomerContact();

cc.setName("Carl");

o.addContact(cc);

em.merge(o);



Then the merge is called for the new CustomerContact object. And I get a EntityNotFoundException.
How can I avoid that?
Thanks in advance.
MaurĂ­cio.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 3:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
how customer contract pojo code looks like?

_________________
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.