Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 317708 - Exception thrown when using LAZY fetch on VIRTUAL mapping
Summary: Exception thrown when using LAZY fetch on VIRTUAL mapping
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: 2010-06-23 10:35 EDT by Guy Pelletier CLA
Modified: 2022-06-09 10:21 EDT (History)
1 user (show)

See Also:


Attachments
Proposed changes (117.20 KB, patch)
2010-07-05 14:04 EDT, Guy Pelletier CLA
no flags Details | Diff
Amendment to original fix (2.12 KB, patch)
2010-07-14 11:25 EDT, Guy Pelletier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Guy Pelletier CLA 2010-06-23 10:35:12 EDT
The following exception is thrown when a lazy setting is used on a virtual mapping. 

Exception in thread "main" java.lang.IllegalStateException: Can't overwrite cause
	at java.lang.Throwable.initCause(Throwable.java:320)
	at org.eclipse.persistence.exceptions.DescriptorException.errorAccessingSetMethodOfEntity(DescriptorException.java:390)
	at org.eclipse.persistence.internal.indirection.WeavedObjectBasicIndirectionPolicy.getSetMethod(WeavedObjectBasicIndirectionPolicy.java:81)
	at org.eclipse.persistence.internal.indirection.WeavedObjectBasicIndirectionPolicy.setRealAttributeValueInObject(WeavedObjectBasicIndirectionPolicy.java:125)
	at org.eclipse.persistence.internal.indirection.WeavedObjectBasicIndirectionPolicy.updateValueInObject(WeavedObjectBasicIndirectionPolicy.java:93)
	at org.eclipse.persistence.internal.indirection.WeavedObjectBasicIndirectionPolicy.getRealAttributeValueFromObject(WeavedObjectBasicIndirectionPolicy.java:61)
	at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeRegisterNewIfRequired(ObjectReferenceMapping.java:820)
	at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeRegisterNewIfRequired(ObjectReferenceMapping.java:800)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeRegisterNewForCreate(ObjectBuilder.java:1684)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4212)
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:384)
	at example.Samples.persistAll(Samples.java:608)
	at example.Main.runDynamicJPATest(Main.java:97)
	at example.Main.main(Main.java:45)

Note: an explicit access="VIRTUAL" will work around the issue, that is,

<one-to-one name="address" fetch="LAZY" target-entity="Address" access="VIRTUAL">

The following though will cause an exception,

<persistence-unit-metadata>
  <persistence-unit-defaults>
    <access>VIRTUAL</access>
  </persistence-unit-defaults>	
</persistence-unit-metadata>

....

<one-to-one name="address" fetch="LAZY" target-entity="Address">

The error lies in:

org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.MappingAccessor, usesPropertyAccess() method, line 1812

return hasAccessMethods() ? true : m_classAccessor.usesPropertyAccess();

Should be:

return hasAccessMethods() ? !usesVirtualAccess() : m_classAccessor.usesPropertyAccess();
Comment 1 Guy Pelletier CLA 2010-07-05 14:04:51 EDT
Created attachment 173464 [details]
Proposed changes

This patch includes the fix for this bug (which specifically is the one line change from MappingAccessor line 1812).

The other changes include the addition of automated testing of dynamic persistence through the jpa/eclipselink extensions interface. Through this testing a couple other issues were uncovered and addressed.

1 - correct processing of parent classes
2 - correct potential infinite loop when no attribute-type is specified for a virtual attribute.
Comment 2 Guy Pelletier CLA 2010-07-05 15:14:42 EDT
Changes have been submitted to the 2.1.1 and 2.2 streams.

Reviewed by: Chris Delahunt, Andrei Ilitchev

Tests: New test suite (EntityMappingsDynamicAdvancedJUnitTestCase) was added and run as part of the extended jpa test suite.
Comment 3 Guy Pelletier CLA 2010-07-14 11:25:38 EDT
Created attachment 174303 [details]
Amendment to original fix

Original patch caused errors during the OSGi testing.

This is an amendment to the original fix.

Reviewed: Andrei Ilitchev, James Sutherland
Verified: Edwin Tang

Existing All existing JPA and extended JPA tests pass without error.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:21:32 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink