openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kaayan <pop...@gmail.com>
Subject Re: same @Id on mapped superclass
Date Thu, 02 Apr 2009 15:11:55 GMT

Thanks for your reply.
The DB is MySQL 5.1 win32 and AppServer is "Tomcat integrated OpenEJB 3.1"
(equipped openjpa-1.1.0.jar).
And this is my scenario...
I have an abstract class MasterObjectBase as

@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class MasterObjectBase implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.TABLE)
  private int id;
  ...some other fields...
}

And some other classes like these that extends the super class...

@Entity
@Table(name="TableName1")
public class TableName1 extends MasterObjectBase {
  @Column(name="description",nullable =false,length =255)
  private String description;
  ...some other fields...
}

@Entity
@Table(name="TableName2")
public class TableName2 extends MasterObjectBase {
  @Column(name="description",nullable =false,length =255)
  private String description;
  ...some other fields...
}

Those subclasses are generated by a code generator, so they must be in the
same coding schema, and they at least worked under JBoss + Hibernate.

About the DB data...I have some old data in DB (was running good under
Hibernate), like this:

TableName1:
id    description   ...
-----------------------------
1     Desc 1        ...
2     Desc 2
...

TableName2:
id    description   ...
-----------------------------
1     Desc 3        ...
2     Desc 4

Because my application utilize Remote EJB to communicate, I have to use
detached Entity objects.
OpenJPA did its work while reading from DB. But when I merge a detached
TableName1(with an existing id value, say 1) object via EntityManager, it
throwed...

org.apache.openjpa.persistence.EntityNotFoundException: Attempted to attach
instance "1" of type "class TableName1", but this instance is already in the
datastore as type "class TableName2".

Seems like OpenJPA is treating those subclasses under a same
'MasterObjectBase' space that they should have a unique ID instead giving
each subclass' own space.

Also, I did another experiment. I dropped all the DB tables, leting OpenJPA
to create them again. Inserted some data objects of TableName1 and
TableName2. I discovered TableName1's id was starting from 1 and
TableName2's was 51. Would the persistence layer crash if TableName1's
records exceeds 51?

And the last experiment is, I run this SQL:
UPDATE TableName2 SET id=1 WHERE id=51

Then when I merge() a detached TableName2 object with id=1, same exception
throwed again.

Sorry for the long text, hope you could understand.

Kaayan





2009/4/2 Rick Curtis (via Nabble)
<ml-user+172967-1743750709@n2.nabble.com<ml-user%2B172967-1743750709@n2.nabble.com>
>

> Kaayan -
>
> We're going to need a more detailed description of your scenario to figure
> out whats going on.
>
> -Rick
>
> Kaayan wrote:
> Hello, I have a similar problem here.
>
> My DB is MySQL, and was running JBoss(which uses Hibernate as Persistence
> Provider), and with some data in DB.
>
> Now I have switched to 'tomcat with openejb 3.1 integration', persistence
> provider is openjpa.
>
> Following the instructions, I have marked the superclass with
> @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS).
>
> But when I call merge(), openjpa throwed an exception '
> org.apache.openjpa.persistence.EntityNotFoundException: Attempted to attach
> instance "3" of type "class A", but this instance is already in the
> datastore as type "class B".'
>
> Any work-arounds on this?
>
> Many thanks!
>
>
>
> ------------------------------
>  This email is a reply to your post @
> http://n2.nabble.com/same-%40Id-on-mapped-superclass-tp2435374p2574796.html
> You can reply by email or by visting the link above.
>
>

-- 
View this message in context: http://n2.nabble.com/same-%40Id-on-mapped-superclass-tp2435374p2575770.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message