openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mkserkan <mkser...@gmail.com>
Subject Mixing inheritance strategies
Date Thu, 13 Dec 2007 14:08:19 GMT

<<
OpenJPA allows you to vary your inheritance strategy for each class, rather
than forcing a single strategy per inheritance hierarchy. See Section 7, “
Additional JPA Mappings ” in the Reference Guide for details.
>>

In my example, i can't make this feature work. Here are three classes User
Admin SuperAdmin :

@javax.persistence.Entity
@Table (name="X_USER")
@Inheritance(strategy=InheritanceType.JOINED)
public class User extends PersistentObject {
.....
}

@javax.persistence.Entity
@Table (name="X_ADMIN")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="discriminator",
discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue("admin")
public class Admin extends User {
...
}

@javax.persistence.Entity
@DiscriminatorValue("superadmin")
public class SuperAdmin extends Admin {
...
}

i first put @Inheritance(strategy=InheritanceType.SINGLE_TABLE) on the Admin
class, but didnt work and throwed an exception:

Type "test.model.Admin" uses a flat inheritance mapping, but declares a
table name of "X_ADMIN", which does not match the superclass table "X_USER".

Then i tried a different thing and changed the annotation configuration..

@javax.persistence.Entity
@Table (name="X_ADMIN")
@DiscriminatorValue("admin")
public class Admin extends User {

@javax.persistence.Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="discriminator",
discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue("superadmin")
public class SuperAdmin extends Admin {

This time it worked OK but with an exception. THERE was NO DISCRIMINATOR
COLUMN in X_ADMIN table. I know i am missing something. I looked at Section
7, “ Additional JPA Mappings ” but there is nothing relevant. So i
appreciate any help.
-- 
View this message in context: http://www.nabble.com/Mixing-inheritance-strategies-tp14316695p14316695.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message