This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 294086 - EntityManager.setProperty problems
Summary: EntityManager.setProperty problems
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-03 11:32 EST by Andrei Ilitchev CLA
Modified: 2022-06-09 10:22 EDT (History)
1 user (show)

See Also:


Attachments
Suggested patch. (33.48 KB, patch)
2009-11-03 11:51 EST, Andrei Ilitchev CLA
no flags Details | Diff
Tests. (6.30 KB, patch)
2009-11-03 14:30 EST, Andrei Ilitchev CLA
no flags Details | Diff
Test correction (6.84 KB, patch)
2009-11-04 10:07 EST, Andrei Ilitchev CLA
no flags Details | Diff
Test correction 2. (583 bytes, patch)
2009-11-05 14:39 EST, Andrei Ilitchev CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Ilitchev CLA 2009-11-03 11:32:59 EST
Property (properties) passed to em.setProperty (em.setProperties) doesn't take effect unless there is no active persistence context.
Also passing ConnectionPolicy properties to setProperty method will lead to ineffective processing - typically there's more than one ConnectionPolicy property specified and they should be processed all together.
Comment 1 Andrei Ilitchev CLA 2009-11-03 11:51:04 EST
Created attachment 151217 [details]
Suggested patch.

The patch implements "Entity Manager Properties" part of http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/properties_processing

Properties applicable to existing uow applied immediately (they still used to set member variables that used to apply to the new uow).

If a propert set that requires a new uow log while there is already existing uow, then the warning is logged and processing is postponed until the new uow is created

Setting any of ConnectionPolicy properties causes the cached ConnectionPolicy to be removed - it's re-created when the new uow is created.

Property processing done in a map (instaed of big if - else if statement). It's uniform for both setProperty and setProperties and more efficient (especially for setProperty).

EntityManager.joinTransaction changed in case no uow exists: in this case only verify whether joining is possible (active jta transaction exists). 
The change postpones creation of the uow that makes it possible to set properties that require a new uow in case of injected entity manager.
The next call to getActivePersistenceContext creates the uow and registeres it with the active transaction (apparently we already - before this change - doing that).

The change in EntitymanagerFactory.getServerSession makes sure that emf will never pick up a non server session property set by another createEMF, yet will pick up all the non server session properties specified in puInfo or System properties.
Comment 2 Andrei Ilitchev CLA 2009-11-03 14:30:56 EST
Created attachment 151235 [details]
Tests.

EntityManagerJUnitTestSuite: 
added new testConnectionPolicySetProperty, alter testConnectionPolicy to run on the server, too.
CacheableModelJunitTest: removed em.clear() in testEMPropertiesOnCommit1 and testEMPropertiesOnCommit2 tests - it's no longer required, CACHE_STORE_MODE property set into entity manager now applied immediately.
Comment 3 Andrei Ilitchev CLA 2009-11-03 14:34:05 EST
Checked into trunk.
Comment 4 Andrei Ilitchev CLA 2009-11-04 10:07:40 EST
Created attachment 151308 [details]
Test correction

Two correction in EntityManagerJUnitTestSuite.internalTestConnectionPolicy:
make sure that if transaction is started then it's always rolled back;
closeEntityManager(em) instead of em.close() - the former works on the server, too.
Comment 5 Andrei Ilitchev CLA 2009-11-05 14:39:13 EST
Created attachment 151483 [details]
Test correction 2.

EntityManager.setProperties method is not defined in JPA 1, the patch cahnges the test that uses this api to run only under JPA 2.0
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:22:06 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink