• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA - Detached Object to persist - Any exemple?

 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JPA - Detached Object to persist - Any exemple?
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe some more info.

In general merge() should be used with detached objects, not persist(). persist() is for new objects.
 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does detached object mean?
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes, an object which is already bound to a context (context could be HTTPSession, ORMSession, JNDI Context etc.,) is detached from the context to make some changes and then bound again. When it is detached it becomes a detached object.
Detached is an identifier of the object state.
Detached Object
literally means, the object is currently in detached state.
 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so, it means if detached must I merge it instead of refrash it? To save changes...
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Refresh would fetch your objects state from the database and hence lose the changed state.
 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And when I fetch objects from database that means "managed objects"?
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic