Results 1 to 3 of 3

Thread: JPA mapped-superclass and ids

  1. #1
    Join Date
    Dec 2005
    Posts
    935

    Default JPA mapped-superclass and ids

    Hello,
    I have a number of domain objects that inherit from a abstract parent, that contains the persistence id (a Long).
    I'm trying to map this in my orm.xml for use with OpenJpa like this:

    Code:
    <?xml version="1.0"?>
    <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 orm_1_0.xsd"
    	version="1.0">
    	<persistence-unit-metadata>
    		<xml-mapping-metadata-complete />
    	</persistence-unit-metadata>
    	<mapped-superclass class="au.com.woolworths.ddd.domain.impl.AbstractDomainObject" access="FIELD">
    		<attributes>
    			<version name="version">
    				<column name="ROW_VER_NO" />
    			</version>
    		</attributes>
    	</mapped-superclass>
    	<mapped-superclass class="au.com.woolworths.ddd.domain.impl.AbstractDomainObjectLong" access="FIELD">
    		<attributes>
    			<id name="id" />
    		</attributes>
    	</mapped-superclass>
    	<entity class="au.com.woolworths.inventory.customer.Customer" access="FIELD">
    		<table name="CUSTOMER" />
    		<sequence-generator name="CustSeq" sequence-name="CUST_SEQ" />
    		<attribute-override name="id">
    			<column name="CUSTOMER_ID" nullable="false" />
    		</attribute-override>
    		<attributes>
    			<id name="id">
    				<column name="CUSTOMER_ID" nullable="false" />
    				<generated-value strategy="SEQUENCE" generator="CustSeq" />
    			</id>
    		</attributes>
    	</entity>
    ...
    </entity-mappings>
    I've tried all sorts of variations of <id>, <attribute-override>, access="FIELD" and access="PROPERTY" etc but keep getting the same error that "id" can't be found in my Customer class:

    Code:
    218  default  INFO   [main] openjpa.Runtime - Starting OpenJPA 0.9.7-incubating
    968  default  WARN   [main] openjpa.Enhance - An exception was thrown while attempting to perform class file transformation on "au/com/woolworths/ddd/domain/impl/AbstractDomainObjectLong":
    <0.9.7-incubating nonfatal general error> org.apache.openjpa.util.GeneralException: org.xml.sax.SAXException: file:/C:/projects/wow-ref/wow-ref-core/target/classes/META-INF/orm.xml [Location: Line: 26, C: 18]: Could not find property/field with the name "id" in type "au.com.woolworths.inventory.customer.Customer". [java.lang.NoSuchFieldException: id]
    	at org.apache.openjpa.persistence.PersistenceMetaDataFactory.parseXML(PersistenceMetaDataFactory.java:236)
    I need to provide a different id sequence generator for each domain object, and have tried just specifing the id in each of the <entity> classes as well as without using attribute-override.
    id does not in exist in Customer but in the parent. In pure Hibermate mapping files, the inherited attributes are found with no problems, but am at a loss at the moment to provide the correct syntax. Note that I am not using annotaions at all in the domain object classes, I'm just using the entity mappings in the orm.xml
    I'm new to JPA, so let me know if I'm missing something.
    Thanks
    Alan

  2. #2
    Join Date
    Dec 2005
    Posts
    935

    Default

    I think my problem is that I can't specify a
    <generated-value strategy="SEQUENCE" generator="CustSeq" /> element
    inside the <attribute-override> element like this:

    Code:
    	<mapped-superclass class="au.com.woolworths.ddd.domain.impl.AbstractDomainObjectLong" access="FIELD">
    		<attributes>
    			<id name="id" />
    		</attributes>
    	</mapped-superclass>
    	<entity class="au.com.woolworths.inventory.customer.Customer" access="FIELD">
    		<table name="CUSTOMER" />
    		<sequence-generator name="CustSeq" sequence-name="CUST_SEQ" />
    		<attribute-override name="id">
    			<column name="CUSTOMER_ID" nullable="false" />
    			<generated-value strategy="SEQUENCE" generator="CustSeq" />
    		</attribute-override>
    Commenting out the generated-value gets me past the orginal problem, but I need to be able to specify a different sequence for each table attached to an entity

  3. #3
    Join Date
    Oct 2008
    Posts
    3

    Default

    I have exactly the same problem as described above. Did anyone manage to figure this out?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •