Hi,

I thought it should be trivial but its not working and I found several other people that had that same issue but unfortunatly, the thread doesn't end with a solution but on the other hand people didn't answer or continue the discussion so there is probably a solution :-)

Some examples found :
http://n2.nabble.com/Identity-Problem-with-MappedSuperclass-td208511.html#a208521
http://n2.nabble.com/same-Id-on-mapped-superclass-td2435374.html#a2574513

We have exactly the same code : an abstract non persistant super class :

@MappedSuperclass
// The following had been replaced by nothing, thanks to pure JPA.
// @AccessType("field")
public abstract class IdentifiableObject extends AbstractObject implements Serializable {
    /**
     * Default technical primary key.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
[CUT]

and several sub-class that use this super-class.
Important : this is done only to save code without intention to persist anything at abstract super level. Only leaf classes are persistant, each one in each own table and had a column id for the primary key.

It failed for us when trying to merge previously detached instance of one subclass. apparently, id are mixed.

Let me clarify :
A and B classes both inherit from previous IdentifiableObject.
It happen (just randomly) that an instance of A and B had the same id and it failed the persistence with that message :

<openjpa-1.2.1-r752877:753278 nonfatal store error> org.apache.openjpa.persistence.EntityNotFoundException: Attempted to attach instance "novlog.metamodel.IdentifiableObject-90" of type "class A", but this instance is already in the datastore as type "class B".
FailedObject: a...@39a4036f

So, in summary, is it possible to have such design pattern of inherited id ? I guess yes.
than, how to code that ? Is there some special annotation ?
We already try to express an inheritance strategy with @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) but the same error occurs.

Finally, I also seek for possible bug and found
https://issues.apache.org/jira/browse/OPENJPA-755
https://issues.apache.org/jira/browse/OPENJPA-792
It look very similar...

Any advice, solution if you encountered that same issue ?

Thanks !

Reply via email to