-->
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: Obtaining generated entity ID from JPA persist()
PostPosted: Wed Aug 27, 2008 3:32 pm 
Newbie

Joined: Wed Aug 27, 2008 3:23 pm
Posts: 1
I hope this is not a FAQ and that it's OK to ask JPA questions on this forum. I'm using JBoss with JPA and Hibernate.....

With Hibernate, I am able to retrieve the generated ID of a newly saved object via:

Serializable id = Session.save(newObject);

However, switching to JPA this is not an option since persist() does not return the new ID.

newObject.getId() is null after the call to persist(). I have also followed up with a call to flush() but this does not make a difference.

I have also tried using Hibernate save():

Serializable id = ((Session)em.getDelegate()).save(newObject)

where "em" is the JPA entity manager. This does not return a value either.

Have I missed something obvious? How can one obtain the ID of a newly persisted entity using JPA?

Thanks!


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.