java - JPA deep inheritence annotation attributes -



java - JPA deep inheritence annotation attributes -

i have hierarchical jpa mapping several classes deep. this

@entity @inheritance(strategy= inheritancetype.single_table) public abstract class baseentityclass implements serializable { // lots of stuff mutual entities. } @entity @inheritance(strategy= inheritancetype.table_per_class) public abstract class entitytypeone extends baseentityclass { // stuff mutual entitytypeone } @entity @inheritance(strategy= inheritancetype.table_per_class) public abstract class entitytypetwo extends baseentityclass { // stuff mutual entitytypetwo }

i know utilize @inheritence method superclass define mapping strategy. how work deep hierarchies? want leaf classes mapped own tables. should single_table baseentityclass?

your base of operations class should marked table_per_class. here's illustration openjpa:

@entity @table(name="mag") @inheritance(strategy=inheritancetype.table_per_class) public class mag { ... } @entity @table(name="tabloid") public class tabloid extends mag { ... }

according jpa javadocs, @inheritance annotation should specified on root of class hierarchy:

defines inheritance strategy used entity class hierarchy. specified on entity class root of entity class hierarchy.

it not specified specification if annotation can placed on subclass , such behavior undefined.

so reply question have asked in comments, if have hierarchy:

subsub -> sub -> base of operations

you need annotate base @inheritance(strategy = table_per_class).

java java-ee inheritance jpa orm

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -