• 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: 662
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: 662
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: 662
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!