Bug 476710 - Unexpected MappingException on component class after save/refresh/save cycle on containing entity
Summary: Unexpected MappingException on component class after save/refresh/save cycle ...
Status: NEW
Alias: None
Product: EMF
Classification: Modeling
Component: Teneo (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 8
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Martin Taal CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-05 17:17 EDT by Phil B CLA
Modified: 2015-09-05 17:17 EDT (History)
0 users

See Also:


Attachments
Project demonstrating refresh problem (48.96 KB, application/x-zip-compressed)
2015-09-05 17:17 EDT, Phil B CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Phil B CLA 2015-09-05 17:17:25 EDT
Created attachment 256403 [details]
Project demonstrating refresh problem

I have an RCP project with an EMF model that contains a Whole class, which in turn refers to a Part. The reference is a containment reference, annotated with @Embedded. The Part class is annotated with @Embeddable,

The application loads objects from the database and then places them into HibernateResources.

When the application subsequently calls:
parentResource.save(...);

then a bit later...
session.refresh(whole); // Refresh is cascaded

and later still...
wholeResource.save(...);

I get:

org.hibernate.MappingException: Unknown entity: Part
	at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1096)
	at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1452)
	at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:242)
	at org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:293)
	at org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierUtil.getID(IdentifierUtil.java:143)
	at org.eclipse.emf.teneo.hibernate.resource.HibernateResource.saveResource(HibernateResource.java:390)
	at org.eclipse.emf.teneo.resource.StoreResource.save(StoreResource.java:422)
...


From stepping through in the debugger I can see that when the application calls Session.refresh(whole) Hibernate replaces the original Part object with a new Part with the same value as the original. When this happens EMF and the StoreResource move the original Part to the StoreResource's removeEObjects collection.

Then later, when the 2nd save occurs, HibernateResource#saveResource attempts to get an identifier for the deleted object so that it can delete it. Unfortunately the Part is a component in the Hibernate mapping rather than an entity, and so has no id, and at this point Hibernate throws the MappingException.

I don't think that the HibernateResource should try to delete the original Part object as it is a component.

I'm using Teneo 2.1.0 and hibernate 4.3.5

The attached project demonstrates the problem. Instructions for running the project are in the description of the pom.xml.