Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[JPA] merge() is inserting instead of updating

 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
can anyone enlighten me regarding the mecanism of persistence in EJB 3.0 ?
I am trying to update an entity in the database from a web client that calls a method in a stateful session bean.
That method looks like this :



It does not update the entity, it inserts a new row in the table.
What do i need to do so that it updates the row ?
Am i missing something regarding the lifecycle of the entity beans ?

Thanks for helping.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the id/primary key of the entity? Is there an existing row in the table with that id? Merge will insert the object if it does not exist, so if you want an update, ensure the object does exist.

You could try first doing a find() on the entity, and ensure it exists before calling the merge.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic