Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EntityManager.refresh() - Detatched Entity - IllegalArgumentException  RSS feed

 
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.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!