This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic