-->
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.  [ 1 post ] 
Author Message
 Post subject: The object returned by merge() has all null in @Id fields
PostPosted: Wed Sep 14, 2011 2:01 pm 
Newbie

Joined: Wed Sep 14, 2011 1:05 pm
Posts: 3
Hi,

I use the merge() procedure to create a new object in DB or update an existing object if it already exists. The problem arises when:

1. I merge an object which does not exist and supposed to be created
2. The object's entity hash two @Id fields, one of them is @ManyToOne reference.

After the merge():

1. All non-id fields are copied to the object returned by merge()
2. The object returned by merge is added to persistence context, and Hibernate tries to create it in DB at commit, but...

Both @Id fields of the object are nulls.

I use 3.6.3.Final

The code outline:
Code:
EntityManager em = ...;

IdObject idKey = em.find(IdObject.class, "someIdOfExistingObject");
assert idKey != null; // The first key part successfully loaded

SomeEntity entityKey = new SomeEntity(); // Create template object to copy from
entityKey.setId2("someId");  // Second key part
entityKey.setSomeField("12345"); // Some data to copy
entityKey.setIdObject(idKey); // First key part

SomeEntity o = em.merge(entityKey);
o.getSomeField(); => "12345", as expected
o.getId2(); => null!
o.getIdObject(); => null!


Is it normal? Or did I miss something?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.