Skip to main content

[jpa-spec users] Re: Rollback and checking to see whether a class is an entity class

  • From: Linda DeMichiel <linda.demichiel@...>
  • To: users@...
  • Subject: [jpa-spec users] Re: Rollback and checking to see whether a class is an entity class
  • Date: Mon, 20 Jan 2014 10:57:45 -0800
  • Organization: Oracle Corporation

Hi Laird,

On 1/20/14 10:14 AM, Laird Nelson wrote:
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
transaction."

Is this intended to cover the EntityManager#contains(Object) method?

Sure.  It should be part of the application's logic to know what is an
entity or not.

  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.


What's the use case you are trying to address?

regards,

-Linda


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?

Best,
Laird

  --
http://about.me/lairdnelson


[jpa-spec users] Rollback and checking to see whether a class is an entity class

Laird Nelson 01/20/2014

[jpa-spec users] Re: Rollback and checking to see whether a class is an entity class

Linda DeMichiel 01/20/2014

[jpa-spec users] Re: Rollback and checking to see whether a class is an entity class

Laird Nelson 01/20/2014
 
 
Close
loading
Please Confirm
Close