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

Bug 341415

Summary: Exception thrown when JPA version is 2.0 but ORM version is 1.0
Product: [WebTools] Dali JPA Tools Reporter: Pascal Filion <pascal.filion>
Component: GeneralAssignee: Brian Vosburgh <brian.vosburgh>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P2 CC: jolene.moffitt, neil.hauge, raghunathan.srinivasan
Version: unspecifiedFlags: neil.hauge: pmc_approved? (david_williams)
raghunathan.srinivasan: pmc_approved+
neil.hauge: pmc_approved? (naci.dai)
neil.hauge: pmc_approved? (deboer)
neil.hauge: pmc_approved? (neil.hauge)
neil.hauge: pmc_approved? (kaloyan)
neil.hauge: pmc_approved? (cbridgha)
neil.hauge: review+
Target Milestone: 3.0 RC2   
Hardware: All   
OS: All   
Whiteboard: PMC_approved
Attachments:
Description Flags
patch 1 none

Description Pascal Filion CLA 2011-03-30 14:54:53 EDT
Build Identifier: I20110309-1800

Exception thrown when the ORM version changes from 2.0 to 1.0 when it has entities.

Reproducible: Always

Steps to Reproduce:
1. Create a new JPA project with JPA version 2.0
2. Create a new entity
3. Create a new JPA ORM Mapping File
4. Add the new entity to the ORM Mapping as an entity
5. In the source editor of the orm.xml, change version 2.0 to 1.0

This exception is thrown:
!ENTRY org.eclipse.core.jobs 4 2 2011-03-30 14:53:00.416
!MESSAGE An internal error occurred during: "Synchronize JPA project: 'te'".
!STACK 0
java.lang.ClassCastException: org.eclipse.jpt.jpa.core.internal.context.orm.GenericOrmXmlContextNodeFactory cannot be cast to org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmXml2_0ContextNodeFactory
	at org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode.getContextNodeFactory2_0(AbstractOrmXmlContextNode.java:47)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmEntity.buildCacheable(GenericOrmEntity.java:58)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmEntity.<init>(GenericOrmEntity.java:31)
	at org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNodeFactory.buildOrmEntity(AbstractOrmXmlContextNodeFactory.java:184)
	at org.eclipse.jpt.jpa.core.internal.context.orm.OrmEntityDefinition.buildContextMapping(OrmEntityDefinition.java:65)
	at org.eclipse.jpt.jpa.core.internal.context.orm.OrmEntityDefinition.buildContextMapping(OrmEntityDefinition.java:1)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmPersistentType.buildMapping(GenericOrmPersistentType.java:170)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmPersistentType.<init>(GenericOrmPersistentType.java:109)
	at org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNodeFactory.buildOrmPersistentType(AbstractOrmXmlContextNodeFactory.java:180)
	at org.eclipse.jpt.jpa.core.internal.context.orm.AbstractEntityMappings.buildPersistentType(AbstractEntityMappings.java:557)
	at org.eclipse.jpt.jpa.core.internal.context.orm.AbstractEntityMappings.initializePersistentTypes(AbstractEntityMappings.java:599)
	at org.eclipse.jpt.jpa.core.internal.context.orm.AbstractEntityMappings.<init>(AbstractEntityMappings.java:117)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericEntityMappings.<init>(GenericEntityMappings.java:25)
	at org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNodeFactory.buildEntityMappings(AbstractOrmXmlContextNodeFactory.java:168)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmXml.buildRoot(GenericOrmXml.java:138)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmXml.synchronizeWithResourceModel(GenericOrmXml.java:106)
	at org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractMappingFileRef.syncMappingFile(AbstractMappingFileRef.java:116)
	at org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractMappingFileRef.synchronizeWithResourceModel(AbstractMappingFileRef.java:72)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence.GenericMappingFileRef.synchronizeWithResourceModel(GenericMappingFileRef.java:49)
	at org.eclipse.jpt.jpa.core.internal.context.ContextContainerTools.sync(ContextContainerTools.java:137)
	at org.eclipse.jpt.jpa.core.internal.context.ContextContainerTools.synchronizeWithResourceModel(ContextContainerTools.java:81)
	at org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit.syncSpecifiedMappingFileRefs(AbstractPersistenceUnit.java:573)
	at org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit.synchronizeWithResourceModel(AbstractPersistenceUnit.java:222)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence.GenericPersistence.syncPersistenceUnits(GenericPersistence.java:143)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence.GenericPersistence.synchronizeWithResourceModel(GenericPersistence.java:63)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence.GenericPersistenceXml.synchronizeWithResourceModel(GenericPersistenceXml.java:104)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.GenericRootContextNode.syncPersistenceXml(GenericRootContextNode.java:90)
	at org.eclipse.jpt.jpa.core.internal.jpa1.context.GenericRootContextNode.synchronizeWithResourceModel(GenericRootContextNode.java:66)
	at org.eclipse.jpt.jpa.core.internal.AbstractJpaProject.synchronizeContextModel(AbstractJpaProject.java:1807)
	at org.eclipse.jpt.jpa.core.GenericJpaProjectManager$1.execute(GenericJpaProjectManager.java:432)
	at org.eclipse.jpt.common.core.internal.utility.JobSynchronizer$SynchronizationJob.run(JobSynchronizer.java:160)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Comment 1 Neil Hauge CLA 2011-05-10 17:28:17 EDT
This appears to be a regression.  Investigating.
Comment 2 Brian Vosburgh CLA 2011-05-17 11:12:53 EDT
Created attachment 195874 [details]
patch 1

Two main changes:

1. Check whether the orm.xml file is version 2.0 (instead of checking whether the project is JPA 2.0) before casting to an orm.xml 2.0 factory.

2. Cache the definition that supplies the orm.xml factory in the OrmXml context model object so it does not change unexpectedly (as opposed to searching for the definition *every* time it is needed).

3. Add check for change in file version (for both persistence.xml and orm.xml) to "sync with resource model". (This check used to only happen during "update"; but the version can be easily changed via the editor, which will trigger a "sync".)
Comment 3 Neil Hauge CLA 2011-05-17 11:48:04 EDT
Patch code looks good.  No problems found with ad-hoc testing.  Also fixes bug 339399 as expected.
Comment 4 Neil Hauge CLA 2011-05-17 12:09:30 EDT
    Explain why you believe this is a stop-ship defect. Or, if it is a "hotbug" (requested by an adopter) please document it as such. 

This is a major regression in functionality where 1.0 standard mapping files will no longer function in a JPA 2.0 faceted project.  This prevents a user who is migrating from JPA 1.0 to 2.0 to gradually move mapping files up to 2.0 level, if they choose to do so at all.

    Is there a work-around? If so, why do you believe the work-around is insufficient? 

There is no workaround except for the user to change the version of the mapping file from 1.0 to 2.0, which may not be reasonable to do.

    How has the fix been tested? Is there a test case attached to the bugzilla record? Has a JUnit Test been added? 

Brian and I have tested this fix manually, in addition to the running the extensive Dali JUnit test suite.

    Give a brief technical overview. Who has reviewed this fix? 

See comment #2 for technical overview. I have reviewed the fix.

    What is the risk associated with this fix? 

Low-medium, but I think more on the low side.
Comment 5 Brian Vosburgh CLA 2011-05-17 17:25:25 EDT
Patch checked into HEAD for RC1.
Comment 6 Jolene Moffitt CLA 2011-06-14 11:27:25 EDT
Verified in Build I-3.3.0RC4-20110603221533

Verified no errors appear in error log when you change the version value in the orm.xml source.  See the link to view test steps for verification. 
http://wiki.eclipse.org/Dali_3.0_RC2
Comment 7 Jolene Moffitt CLA 2011-06-14 11:28:43 EDT
Verified in Build I-3.3.0RC4-20110603221533

Verified warning appears correctly if using EL platform and no warning appears
if using Generic platform.  see the link to view test steps for verification. 
http://wiki.eclipse.org/Dali_3.0_RC2