Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 317708

Summary: Exception thrown when using LAZY fetch on VIRTUAL mapping
Product: z_Archived Reporter: Guy Pelletier <guy.pelletier>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipselink.orm-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed changes
none
Amendment to original fix none

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