ejb3 inheritance and overriding of persistence attributes in subclass

Hello!

I'm having trouble with the OR-mapping and an inheritance class structure.

Here is a code example of what I try to do:

@MappedSuperclass

@IdClass(CustomerPK.class)

public abstract class Customer extends

AnotherNonPersistentAndNotMappedSuperclass {

private int custNo;

private String name;

private String firstName;

@Id

@Column(name="CUST_NO")

public int getCustNo() { return custNo; }

public void setCustNo() { this.custNo = custNo; }

@Column(name="NAME")

public String getName() { return name; }

public void setName(String name) { this.name = name; }

@Column(name="FIRST_NAME")

public String getFirstName() { return firstName; }

public void setFirstName(String firstName) {

this.firstName = firstName;

}

}

@Entity

@Table(name="CUSTOMER_SUB_1")

@IdClass(CustomerSub1PK.class)

public class CustomerSub1 extends Customer {

}

@Entity

@Table(name="CUSTOMER_SUB_2")

@IdClass(CustomerSub2PK.class)

public class CustomerSub2 extends Customer {

private String name;

@Id

@Column(name="NAME")

public String getName() { return name; }

public void setName(String name) { this.name = name; }

}

Further, I have created the primary key classes as listed now:

public abstract class CustomerPK implements Serializable {

private int custNo;

public CustomerPK() {}

public CustomerPK(int custNo) {...}

public int getCustNo() { return custNo; }

public void setCustNo() { this.custNo = custNo; }

public boolean equals(Object obj) {...}

public int hashCode() {...}

}

public class CustomerSub1PK implements Serializable {

}

public class CustomerSub2PK implements Serializable {

private String name;

public CustomerSub2PK() {}

public CustomerSub2PK(int custNo, String name) {...}

public String getName() { return name; }

public void setName(String name) { this.name = name; }

public boolean equals(Object obj) {...}

public int hashCode() {...}

}

And here comes my problem:

I need this structure, because I want to deliver a Collection of Customer objects to a client. The client should be able to use the methods of the Costomer class to read the data of the Entity-Beans without knowing weather the specific object was created as CustomerSub1 or as CustomerSub2. Further, the attribute 'name' is declared as additional primary key field in class CustomerSub2. But this field 'name' is as well declared in the baseclass Customer as a non-primary key field, because for some reasons I can't explain here, 'name' is needed in CustomerSub1 too, but not as an primary key field.

Persisting objects of type CustomerSub1 with an Entitymanager works pretty well. But persisting CustomerSub2-objects doesn't work at all. I'm working with a BEA WLS 10.0 TechPreview and it just throws a

weblogic.transaction.internal.AppSetRollbackOnlyException.

I think it has to do with the fact, that CustomerSub2 is not able to override an attribute and its getter/setter-methods, which are already declared in its base-class.

So, has anyone an idea where the problem is in my code?!? Are there any mistakes in my code which cause the AppSetRollbackOnlyException? Is it just a bug in the BEA WLS or is this kind of inheritance not supported by the JPA in general? Does anyone know a workarround with which I don't have to give up my entire inheritance structure?

I appreciate every help and every idea!

Thanks,

red_max_ivv

[3702 byte] By [red_max_ivva] at [2007-11-26 22:31:15]
# 1

Hi,

You can't specify an Id more than once in an entity class hierarchy.

See spec section:

2.1.4 Primary Keys and Entity Identity

The primary key must be defined on the entity that is the root of the entity hierarchy or on a mapped superclass of the entity hierarchy. The primary key must be defined exactly once in an entity hierarchy.

Regards,

-marina

jdcmarinaa at 2007-7-10 11:36:41 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...