[
https://issues.apache.org/jira/browse/OPENJPA-3006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18134692#comment-18134692
]
ASF subversion and git services commented on OPENJPA-3006:
----------------------------------------------------------
Commit 3f8a737eb371fa6bb8d838c2cdb024e916b568b4 in openjpa's branch
refs/heads/asciidoc from Wu Shuwen
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=3f8a737eb ]
[OPENJPA-3006] Keep entity manager values out of factory properties (#230)
* [OPENJPA-3006] Keep entity manager values out of factory properties
* [OPENJPA-3006] Document factory property behavior change
* [OPENJPA-3006] Use try-with-resources in property test
> EntityManagerFactory.getProperties() is not usable as configuration input
> -------------------------------------------------------------------------
>
> Key: OPENJPA-3006
> URL: https://issues.apache.org/jira/browse/OPENJPA-3006
> Project: OpenJPA
> Issue Type: Bug
> Components: jpa
> Reporter: Richard Zowalla
> Assignee: Richard Zowalla
> Priority: Minor
> Fix For: 4.2.0
>
>
> EntityManagerFactory.getProperties() merges the EntityManager level defaults
> (harvested from the Broker and FetchPlan) into the factory properties. Those
> values are *user readable*: enums, live instances and unprefixed keys. The
> resulting map cannot be fed back into
> Persistence.createEntityManagerFactory(name, map), which is a pattern our own
> tests use (TestSchemaGenDrop step 4 does new HashMap<>(emf.getProperties())).
> Three distinct problems, all reproducible by creating an EntityManager and
> then passing emf.getProperties() to createEntityManagerFactory:
> 1. Enumerated values. openjpa.AutoClear is reported as
> AutoClearType.DATASTORE, while IntValue.setInternalObject requires a Number,
> giving "ParseException: AutoClear: DATASTORE". Value.unalias compares alias
> names case sensitively, so the string form DATASTORE would not match the
> alias datastore either. The same applies to openjpa.DetachState,
> openjpa.ConnectionRetainMode and openjpa.AutoDetach (an EnumSet).
> 2. Live instances. openjpa.EntityManagerFactory and openjpa.ManagedRuntime
> are reported as the objects themselves rather than as their plugin strings.
> 3. Key collisions. The EntityManager contributes unprefixed keys, so the map
> holds both FetchBatchSize and openjpa.FetchBatchSize, and
> ProductDerivations.getConfigurationKey fails with "IllegalStateException:
> Found multiple properties with different valid prefixes".
> Today the failures are masked by accident:
> EntityManagerFactoryImpl.getProperties() caches its result, so whether the
> EntityManager level values are present at all depends on whether an
> EntityManager was created before the first call.
> TestPropertiesMethods.testEMFPropertyValueTypeIsPreserved passes because they
> are present (it asserts openjpa.AutoClear is an AutoClearType), and
> TestSchemaGenDrop passes because they are not. See OPENJPA-2982, where making
> the merge deterministic exposed all of the above.
> What needs deciding is the contract of the map. Either it stays a human
> readable report, in which case the round trip should be documented as
> unsupported and the tests should stop relying on it, or it becomes valid
> configuration input, which means reporting config-safe values for prefixed
> keys, dropping the unprefixed duplicates, and making Value/ProductDerivations
> tolerant of enum values and prefix collisions.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)