Get your CodeRanch badge!*
The moose likes Object Relational Mapping and the fly likes How I can get the primary key assigned to an object when I use em.persist method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How I can get the primary key assigned to an object when I use em.persist method?" Watch "How I can get the primary key assigned to an object when I use em.persist method?" New topic
Author

How I can get the primary key assigned to an object when I use em.persist method?

raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 550
Hi
Thank you for reading my post.
I have an object when I store it using entityManager.persist method.
Now I need to get the primary key assigned to my entities in my java code. for example to return them to my users as reference key.
I have not been able to find a method in entityManager which can do this for me. Please let me know How I can do this.

Thanks.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

object.getId() after the persist? Or is it not assigned at that point?

Can you not just call the getId() method of the object in question?

I know the save method of the Hibernate Session actually returns the primary key.

-Cameron McKenzie
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How I can get the primary key assigned to an object when I use em.persist method?
 
Similar Threads
PrimaryKey Class
Using EJB and Oracle
ejbFind() in Entity Bean
update record for selection of id
How to avoid duplicate inserts in JPA HQL (EJB 3.0 - Java EE 5)