Topic
No replies
Emmerling
Emmerling
1 Post
ACCEPTED ANSWER

Pinned topic Mapped superclass - multi-level inh. works FEP 1.0.0.3 but fails later FEPs

‏2013-02-18T19:02:58Z |
I hope this posting has enough info, if not I'll try to provide more.

So there is a family of tables all mapped to different classes but having some columns in common i.e. CODE, START_DATE, END_DATE.

Some time ago, a mapped superclass was created using XML:


<?xml version=
"1.0" encoding=
"UTF-8"?> <entity-mappings xmlns=
"http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
"http://java.sun.com/xml/ns/persistence/orm  http:
//java.sun.com/xml/ns/persistence/orm_2_0.xsd" version=
"2.0"> <mapped-superclass class=
"com.mydomain.app.core.domain.referencetables.ReferenceTableEntryImpl"> <id-

class class=
"com.mydomain.app.core.keys.referencetable.AbstractReferenceTableEntryKey"/> <attributes> <id name=
"code"></id> <basic name=
"endDate"><column name=
"END_DATE" nullable=
"false" /><temporal>TIMESTAMP</temporal></basic> <basic name=
"startDate"><column name=
"START_DATE" nullable=
"false" /><temporal>TIMESTAMP</temporal></basic> </attributes> </mapped-superclass> </entity-mappings>


Note that ReferenceTableEntryImpl is an abstract class and the individual mapped classes all extend it. This strategy has worked for some time.

Recently I was asked to map to a new table that has the CODE column but not START_DATE and END_DATE, and is (from the business perspective) considered a reference table. The preferred approach being to refactor the hierarchy as follows:


<?xml version=
"1.0" encoding=
"UTF-8"?> <entity-mappings xmlns=
"http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
"http://java.sun.com/xml/ns/persistence/orm  http:
//java.sun.com/xml/ns/persistence/orm_2_0.xsd" version=
"2.0"> <mapped-superclass class=
"com.mydomain.app.core.domain.referencetables.ReferenceTableEntryBasicImpl"> <id-

class class=
"com.mydomain.app.core.keys.referencetable.AbstractReferenceTableEntryKey"/> <attributes> <id name=
"code"></id> </attributes> </mapped-superclass> </entity-mappings>   <?xml version=
"1.0" encoding=
"UTF-8"?> <entity-mappings xmlns=
"http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
"http://java.sun.com/xml/ns/persistence/orm  http:
//java.sun.com/xml/ns/persistence/orm_2_0.xsd" version=
"2.0"> <mapped-superclass class=
"com.mydomain.app.core.domain.referencetables.ReferenceTableEntryImpl"> <attributes> <basic name=
"endDate"><column name=
"END_DATE" nullable=
"false" /><temporal>TIMESTAMP</temporal></basic> <basic name=
"startDate"><column name=
"START_DATE" nullable=
"false" /><temporal>TIMESTAMP</temporal></basic> </attributes> </mapped-superclass> </entity-mappings>


Clearly there is more to this but hopefully it can be inferred from what I have shown.

So the problem is, I did this and the result worked in my RSA 8.0.4.1 environment using WAS 7.0.0.15 and JPA 2.0 Feature 1.0.0.3, however in some other environments e.g. WAS 7.0.0.23 and JPA 2.0 Feature 1.0.0.7 it fails with the following error during publishing (presumably as part of enhancement):

Caused by: <openjpa-2.0.2-SNAPSHOT-r422266:1032678 fatal user error> org.apache.openjpa.util.MetaDataException: Superclass field "java.lang.Object.startDate" is mapped in the metadata for subclass "com.mydomain.app.core.domain.referencetables.global.ConcreteReferenceTableEntry", but is not a persistent field.

So in the FEP 1.0.0.3 environment, it can recognize that endDate and startDate are fields in the abstract superclass com.mydomain.app.core.domain.referencetables.ReferenceTableEntryImpl, but in the FEP 1.0.0.7 environment it no longer can. At the moment, I can't say what would happen with 1.0.0.5, but may be able to find out later.

As it happens, I don't need a fix for this (not being wedded to this approach) but it would be highly desirable to have an informed explanation for the problem.

So if anybody thinks they can explain this, it would be greatly appreciated, thanks!

--JE