JPA规范中规定了三种映射继承的关系策略,分别如下所示。
●继承关系的实体保存在一个表(Single Table per Class Hierarchy Strategy)
●每个子类实体保存在一个表(Joined Subclass Strategy)
●每个实体类保存在一个表(Table per Class Strategy)
那么同一个对象树上是否可以有两个或多个继承策略呢?(即是否可以对继承策略进行重载)
答案要问JPA Vendor了,在java-tips.org找到下面一段:
----------------------------------------------------------------------------------------------
It's possible for an entity to specify a different inheritance strategy for its subclasses. The BrokerageAccount entity illustrates that.
Because the Account entity specifies a SINGLE_TABLE per class hierarchy strategy, Account, CheckingAccount, SavingsAccount, CreditCardAccount and BrokerageAccount are stored in the same database table. However the MarginAccount entity's maxLoanAllowed attribute is stored in a separate table because the inheritance strategy was changed to "JOINED" in the BrokerageAccount. [color=red][b]A persistence provider does not need to support this feature, but the Java API specification allows for this.[/b][/color] So to make sure that your code is portable across vendors, it's best to avoid using this feature.
----------------------------------------------------------------------------------------------
[url]http://www.java-tips.org/java-ee-tips/enterprise-java-beans/inheritance-and-the-java-persistenc.html[/url]
●继承关系的实体保存在一个表(Single Table per Class Hierarchy Strategy)
●每个子类实体保存在一个表(Joined Subclass Strategy)
●每个实体类保存在一个表(Table per Class Strategy)
那么同一个对象树上是否可以有两个或多个继承策略呢?(即是否可以对继承策略进行重载)
答案要问JPA Vendor了,在java-tips.org找到下面一段:
----------------------------------------------------------------------------------------------
It's possible for an entity to specify a different inheritance strategy for its subclasses. The BrokerageAccount entity illustrates that.
@Entity
@Inheritance(strategy=InheritanceStrategy.JOINED)
public class BrokerageAccount extends Account{
float tradeFees;
}
@Entity
public class MarginAccount extends BrokerageAccount{
float maxLoanAllowed;
}
Because the Account entity specifies a SINGLE_TABLE per class hierarchy strategy, Account, CheckingAccount, SavingsAccount, CreditCardAccount and BrokerageAccount are stored in the same database table. However the MarginAccount entity's maxLoanAllowed attribute is stored in a separate table because the inheritance strategy was changed to "JOINED" in the BrokerageAccount. [color=red][b]A persistence provider does not need to support this feature, but the Java API specification allows for this.[/b][/color] So to make sure that your code is portable across vendors, it's best to avoid using this feature.
----------------------------------------------------------------------------------------------
[url]http://www.java-tips.org/java-ee-tips/enterprise-java-beans/inheritance-and-the-java-persistenc.html[/url]