[
https://issues.apache.org/jira/browse/OPENJPA-2985?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18106300#comment-18106300
]
ASF subversion and git services commented on OPENJPA-2985:
----------------------------------------------------------
Commit 0821ba774180de9b5dd716f6f1236882d84beb12 in openjpa's branch
refs/heads/OPENJPA-2985 from Richard Zowalla
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=0821ba774 ]
[OPENJPA-2985] Keep EntityManagerFactoryImpl serializable
The getNamedQueries(Class) implementation guarded its lazy metadata load
with a dedicated "private final Object _namedQueriesLock = new Object()".
EntityManagerFactoryImpl is serialized field by field (it implements
OpenJPAEntityManagerFactory, which extends Serializable, and the class
declares no writeObject/readObject), so that non-transient bare Object
field made the whole factory unserializable:
java.io.NotSerializableException: java.lang.Object.
The targeted tests for the new API never serialize a factory, so they
stayed green; CI runs the full suite and
org.apache.openjpa.persistence.simple.TestSerializedFactory, which writes
the EntityManagerFactory to an ObjectOutputStream, failed on all four
jobs. The neighbouring _entityGraphs guard did not have this problem
because it locks on a ConcurrentHashMap, which is itself serializable.
Fix: use a java.util.concurrent.locks.ReentrantLock as the monitor, the
same idiom AbstractBrokerFactory already uses for its internal lock in
the kernel. ReentrantLock is Serializable and deserializes unlocked, so
the field can stay final and non-transient, no serialization hooks are
needed, and the double-checked initialization (volatile flag read
outside, re-checked inside the lock, written last) is unchanged.
No new test: TestSerializedFactory already reproduces the failure exactly
and passes with the fix.
> Mandatory JPA 3.2 methods throw UnsupportedOperationException
> -------------------------------------------------------------
>
> Key: OPENJPA-2985
> URL: https://issues.apache.org/jira/browse/OPENJPA-2985
> Project: OpenJPA
> Issue Type: Sub-task
> Reporter: Maxim Solodovnik
> Priority: Major
>
> Discussion thread:
> https://github.com/apache/openjpa/pull/144#discussion_r3683005795
> **(low)** `getNamedQueries(Class)` still throws
> UnsupportedOperationException, as do
> `EntityManagerImpl.createQuery(TypedQueryReference)`
> (EntityManagerImpl.java:2779) and `find(EntityGraph, Object, FindOption...)`
> (EntityManagerImpl.java:2645). These are mandatory JPA 3.2 API - planned
> before merge, or tracked in a follow-up JIRA? Worth referencing the issue in
> the exception message.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)