openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Baptiste BRIAUD -- Novlog <>
Subject How to define @id in super class ?
Date Tue, 22 Sep 2009 15:34:16 GMT

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 :

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

// 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.
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     private Long id;

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
It look very similar...

Any advice, solution if you encountered that same issue ?

Thanks !

View raw message