Richard Zowalla created OPENJPA-3081:
----------------------------------------

             Summary: EntityManagerFactory.getMetamodel() fails for unenhanced 
entities until the first EntityManager is created
                 Key: OPENJPA-3081
                 URL: https://issues.apache.org/jira/browse/OPENJPA-3081
             Project: OpenJPA
          Issue Type: Bug
            Reporter: Richard Zowalla
            Assignee: Richard Zowalla
             Fix For: 4.2.0


With `openjpa.RuntimeUnenhancedClasses=supported`, the runtime subclasses of 
unenhanced entities are only created and registered in `PCRegistry` when the 
factory creates its first broker (`AbstractBrokerFactory.makeReadOnly` → 
`loadPersistentTypes` → `ManagedClassSubclasser.prepareUnenhancedClasses`). 
Metadata access at factory level does not go through that step.

On a fresh factory, before any `EntityManager` was created:

- `getMetamodel()` throws `MetaDataException: The type "…" has not been 
enhanced`
- `getCriteriaBuilder()` and `getNamedEntityGraphs()` fail the same way, as 
they go through the metamodel
- `getPersistenceUnitUtil().getIdentifier(entity)` throws 
`IllegalArgumentException`, as the type is not registered yet

It only works if some factory in the JVM has already created an `EntityManager` 
for the entity, because `PCRegistry` is static. The result therefore depends on 
what ran before in the same JVM; it was found through a test that only failed 
in some test orders.

**Expected:** these methods prepare the unenhanced types themselves, the same 
way the first `EntityManager` does, once per factory.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to