| It seems that the javadoc on EntityManager#find(Class<T> entityClass, Object primaryKey) doesn't specify an error should be thrown, nor is clear if null should be returned but other sections are more helpful: On section 3.1.1 of the spec (page 79 as it's a very long section - of JSR-338 Maintenance Release doc review of 7/17/2017) it seems to suggest that the entity should be loaded in detached mode, quoting the spec:
Methods that specify a lock mode other than LockModeType.NONE must be invoked within a transaction. If there is no transaction or if the entity manager has not been joined to the transaction, the javax.persistence.TransactionRequiredException is thrown.
The find method (provided it is invoked without a lock or invoked with LockModeType.NONE) and the getReference method are not required to be invoked within a transaction. If an entity manager with transaction-scoped persistence context is in use, the resulting entities will be detached; if an entity manager with an extended persistence context is used, they will be managed. See section 3.3 for entity manager use outside a transaction.
The javadoc on this other signature is also suggesting that an exception is only thrown is lockMode is not NONE and the transaction is missing:
public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode);
We might prefer to do whatever Hibernate did before, but indeed this looks like something IronJacamar should allow. |