Forums Register Login

EntityManager.refresh() - Detatched Entity - IllegalArgumentException

+Pie Number of slices to send: Send

[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..
+Pie Number of slices to send: Send
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.

roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 6898 times.
Similar Threads
EntityManager
EntityManager.refresh() works only on managed entities.
Entity Manager Remove Operation
Detached Entity Exception in JPA (Detached entity passed to persist)
EntityManager.refresh() - Works on Detatched Or Managed Entities ?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:15:06.