JPA EclipseLink Adding/Updating entities

I'm a bit confused with the way JPA handle adding/updating entities. ATM, i have this piece of code: AltContact c = new AltContact("test"); save(c) System.out.println("ENTITY: " + contains(c)); c.setEnterpriseName("test2"); save(c); System.out.println("ENTITY: " + contains(c)); The *save* method is a simple method on the server side of my application requesting a merge on the EntityManager: public void save (Object e) { em.merge(e); em.flush(); } Where *em* is an instance of `EntityManager`. *contains* is once again a method on server side that will ask the entity manager if a given entity exist in the current persistent context. The code above create two rows in my table, the first one with the value "test" and the other one with the value "test2", which is not what i want. I want to create a new row with the value "test" and then, right after the creation of the row, update it and set his value to "test2". I printed out the return of *contains* after both call to *save*, `false` was returned the two times. I guess the problem come from the fact that my entity is not part of the persistent context after the first call to *save* so when i call *save* again, the entity manager consider it's a new entity and create a new row. How can achieve this updating process?
I think this answer (stackoverflow.com/a/1070629/1256525) to a similar question should solve your problem.

以上就是JPA EclipseLink Adding/Updating entities的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏