[jpa-spec users] Rollback and checking to see whether a class is an entity class
- From: Laird Nelson <ljnelson@...>
- To: users@...
- Subject: [jpa-spec users] Rollback and checking to see whether a class is an entity class
- Date: Mon, 20 Jan 2014 10:14:23 -0800
Section 3.1.1 says:
"Runtime exceptions thrown by the methods of the EntityManager interface
other than the LockTimeoutException will cause the current transaction to
be marked for rollback if the persistence context is joined to that
Is this intended to cover the EntityManager#contains(Object) method? That
method declares that it throws an IllegalStateException if the supplied
Object is not an entity. That suggests to me that at runtime if I have an
object in hand whose origin I'm not sure of then I can't simply blindly
pass it to this contains() method, as that might result in transaction
rollback. That seems kind of harsh to me.
It would appear that the only safe way to check to see if an arbitrary
object is both an entity and in the persistence context would be to first
check to see if the object is in the metamodel's list of entities and then
call EntityManager#contains(Object) passing it. This seems really
cumbersome for a very common check.
So: should em.contains(arbitraryObjectFromSomewhere) cause the transaction
to rollback if arbitraryObjectFromSomewhere is not in fact an entity? Is
there another idiom for testing for entity-ness/hood that I'm missing?