• Post Reply Bookmark Topic Watch Topic
  • New Topic

EntityManager.refresh() - Detatched Entity - IllegalArgumentException

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[P-124 of Mikalai Zaikin Notes] states
"For a given entity A, the refresh method behaves as follows, If A is a DETACHED entity, an IllegalArgumentException is thrown"..

I think this is incorrect. With refresh method, a detatched entity becomes managaed..
 
Ross Crockett
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Sandeep,
Im a bit too lazy to find exactly where in the spec this is mentioned, but the statement in Mikalai's notes is correct. Check out the API docs for the EntityManager.refresh() method where it also confirms the statement.


Throws:
IllegalStateException - if this EntityManager has been closed.
IllegalArgumentException - if not an entity or entity is not managed
TransactionRequiredException - if invoked on a container-managed entity manager of type PersistenceContextType.TRANSACTION and there is no transaction.
EntityNotFoundException - if the entity no longer exists in the database.


It can be managed if you add a merge() call in in the refresh() call e.g.

 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!