[
https://issues.apache.org/jira/browse/OPENJPA-3081?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18144684#comment-18144684
]
ASF subversion and git services commented on OPENJPA-3081:
----------------------------------------------------------
Commit 50897c97e6e25b275019fef42be285e6f0b9f151 in openjpa's branch
refs/heads/master from Richard Zowalla
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=50897c97e ]
[OPENJPA-3081] EntityManagerFactory.getMetamodel() fails for unenhanced
entities until the first EntityManager is created (#309)
* [OPENJPA-3081] Load and prepare the persistent types of a broker factory
under its lock the first time, so that concurrent callers do not prepare
unenhanced types twice or use them before they are prepared
* [OPENJPA-3081] Prepare unenhanced types before
EntityManagerFactory.getMetamodel() and PersistenceUnitUtil.getIdentifier()
need them, so that they work before the first EntityManager is created
* [OPENJPA-3081] Add the getMetamodel() fix for unenhanced entities to the
release notes
* [OPENJPA-3081] Do not prepare persistent types on a closed
EntityManagerFactory, prepare them at most once per factory, and check
isManageable in getIdentifier() only once per state
* [OPENJPA-3081] Brace the if bodies of loadPersistentTypes and sort the
imports of EntityManagerFactoryImpl
* [OPENJPA-3081] Test that unenhanced types are prepared only once, also for
concurrent first callers, check that the test entities are unenhanced, and drop
the named query test that passed without the fix
* Best practices after rebase
---------
Co-authored-by: Maxim Solodovnik <[email protected]>
> 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
> Priority: Major
> 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)