aspose file tools*
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
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: 551
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
    
    1

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
 
 
subject: How I can get the primary key assigned to an object when I use em.persist method?