paulk-asert opened a new pull request, #314:
URL: https://github.com/apache/openjpa/pull/314

   [OPENJPA-3090](https://issues.apache.org/jira/browse/OPENJPA-3090): 
`EntityManagerFactory.callInTransaction()` fails for any result that is not an 
entity, such as a `String`, a count or a `List`, after its transaction has 
already committed:
   
   ```
   org.apache.openjpa.persistence.PersistenceException: The class "class 
java.lang.String" is not an entity.
       at 
org.apache.openjpa.persistence.EntityManagerImpl.contains(EntityManagerImpl.java:1112)
       at 
org.apache.openjpa.persistence.EntityManagerFactoryImpl.callInTransaction(EntityManagerFactoryImpl.java:906)
   ```
   
   After the commit, `callInTransaction()` re-finds a returned entity that is 
not enhanced (see the review discussion in #144, 
https://github.com/apache/openjpa/pull/144#discussion_r3683004050). To decide 
whether to do that, it calls `em.contains(result)`, which throws 
`IllegalArgumentException` for anything that is not an entity.
   
   This change only calls `contains()` when the result's class is an entity 
type, as the metadata repository reports it (embeddable-only types excluded). 
Entity results behave as before.
   
   Testing:
   - New 
`TestEntityManagerFactoryTransactions.callInTransactionNonEntityResult` covers 
`String`, `Long` (count query), `List` and `null` results. It fails without the 
fix ("is not an entity") and passes with it.
   - `TestEntityManagerFactoryTransactions`, `TestEntityManagerFactoryTCK`, 
`TestPersistenceUnitUtil` and `TestEntityManagerFactoryLoading` pass (54 tests).
   - Outside the test suite, also checked with build-time enhanced entities and 
with `openjpa.RuntimeUnenhancedClasses=supported`: non-entity results are 
returned as-is, and persisted and found entities (including runtime subclasses) 
are returned as before.
   
   Possible follow-ups, not changed here: whether the post-commit re-find is 
needed at all, and keeping post-commit work out of the `try` whose `catch` 
rolls back.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to