• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

EntityManager.refresh() - Detatched Entity - IllegalArgumentException

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic