|JPA + Native interference [message #1001854]
||Thu, 17 January 2013 12:57
| Roger Spall
Registered: January 2013
To summarize, I am working on a project to migrate from Native Eclipselink (Mapping workbench / Native Eclipselink queries / ExpressionBuilders, ReadObject queries, etc) to JPA.|
Anyway, the migration plan requires that the same POJO business objects are (temporarily) mapped through both JPA AND Mapping workbench / Native mappings - in this case we are using the old 'Project java source' generated from the Mapping Workbench to represent the runtime native mappings.
Without excessive detail, we basically want to facilitate testing so we can compare POJO's persisted through both the old Native EclipseLink and new JPA, and confirm no JPA mapping errors exit - unfortunately there are hundreds of POJOs and we have to manually create the new JPA POJO mappings from the old Native Mapping Workbench project!
Anyway we have run into an annoying problem...
We had assumed (no documentation / spec anywhere about this) that both Native and JPA projects / mappings can co-exist for the same POJO's provided we use the different methods for accessing them, i.e. an EntityManager (JPA) versus an EclipseLink Server / sessions. Obviously our old code works just fine, and we just added special test cases using an EntityManager to compare old to new persisted POJOs.
What we have found is that marking a POJO relationship as Transient in JPA also causes that same POJO relationship to be null / transient in Native Eclipselink.
Imagine a Bank with a collection of Accounts. This collection is mapped as a 1 - many relationship in the MappingWorkbench and has been working fine for years in production - read via Native Eclipselink queries. Now we have added a JPA mapping for Bank, but marked this Accounts relationship as Transient. Of course, as expected reading any Bank objects through JPA / EntityManager we find null Accounts. However, we now find that reading any Bank objects in Native Eclipselink (our old code) suddenly returns Banks with null / no Accounts! When I remove this JPA transient marker for a Bank's Accounts, the problem goes away.
Can anyone cast light on this issue and / or confirm that you cannot have the same POJO's mapped with both JPA and Native mappings at the same time?
1) Just in case someone astutely observes that if it hurts when you hit your head against the wall, just stop hitting your head
** With so many Natively mapped POJO's we really need a testing strategy to make sure that the new JPA mappings correctly correspond to the old Native mappings. This means we have to compare old and new mappings for the same POJO's in the same codebase, AND it makes it simpler if we convert all of the primitive mappings (setting relationships to Transient) and test those first, before we compare the relationships.
2) It makes no difference whether we use JPA annotations or ORM.xml, Trnsient causes the same problem either way
3) Marking a primitive as Transient / unmapped in JPA doesn't stop Native Eclipselink from correctly loading that primitive's value, i.e. Transient only breaks Native Eclipselink relationships
4) No surprises, but just to be sure, when I use an ORM.xml file and map the POJO using a different JPA provider, Transient doesn't impact Native Eclipselink mappings
- This may end up being our work around, i.e. test our mappings by comparing the same POJOs mapped through Native Eclipselink and a non-eclipselink JPA (e.g. OpenJPA).
- Once this part of the testing is complete (old mappings are equivalent to and return identical content to JPA mappings) we can switch off / out the Native Eclipselink mappings and switch the JPA provider back to Eclipselink
Powered by FUDForum
. Page generated in 0.17840 seconds