-->
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: merge doesn't update the Id for transient object
PostPosted: Sat Sep 23, 2006 5:48 am 
Newbie

Joined: Tue Mar 21, 2006 1:29 pm
Posts: 9
Hi,

I made a small test using merge and I noticed that after the merge of a transient object the Id of this one is not updated with the generated id.

The insert in the db is successfull.

Here is my test:
Code:
   public void testPersistEJB() {
      EntityManagerFactory emf = (EntityManagerFactory) context.getBean("entityManagerFactory");
      EntityManager em = emf.createEntityManager();
      EntityTransaction tx=em.getTransaction();
      tx.begin();
      Contact contact = new Contact();
      contact.setName("Dupondt");
      em.merge(contact);
      tx.commit();
      em.close();
      emf.close();
      assertNotNull(contact.getId());
   }


My Contact class extends a PersistentObject which contains the id definition:

Code:
   @Id @GeneratedValue(generator="system-uuid")
   @GenericGenerator(name="system-uuid", strategy = "uuid")
   private String id;

A workaround could be to check my self if I have to do a merge or persist, but regarding wiht chap 3.7 of the Hibernate EntityManager, the merge should be deal with it and react as a persist. Isn't it?

Now, I wonder, if I missunderstoud the merge functionality or the merge has really a problem?

Regards
Dominique


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 10:02 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
didn't yuou forget @GeneratedValue?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 10:20 am 
Newbie

Joined: Tue Mar 21, 2006 1:29 pm
Posts: 9
Emmanuel,

I don't understand you comment, because If you look at the above code, you will see that the @GeneratedValue is present.

Dominique


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 10:42 am 
Beginner
Beginner

Joined: Mon Jan 09, 2006 3:05 pm
Posts: 24
The problem is

Code:
em.merge(contact);


It should read:

Code:
contact = em.merge(contact);


--keenan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 12:27 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
vernid wrote:
Emmanuel,

I don't understand you comment, because If you look at the above code, you will see that the @GeneratedValue is present.

Dominique

I didn't see it.
keenan is right

_________________
Emmanuel


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.