我想它是否能夠處理的協會與抽象實體的接口關聯(即:一個接口),在另一個實體。例如:
我有一個class
調用Foo
它有一個屬性bar
,它是Bar
類型,它是一個interface
。多個類別(Bar1
,Bar2
)實現Bar
並且都是全部也可持久。處理使用ORM在Java中
class Foo{
Bar bar; // this will be either Bar1 or Bar2
}
interface Bar{
// some methods
}
class Bar1 implements Bar{
String s; // Bar1 and Bar2 have different represantations ,hence they must be persisted to different tables
}
class Bar2 implements Bar{
int i;
}
現在我該如何使用Java中的ORM來處理這個問題?即:因此,當我檢索Foo
時,它的bar
是Bar
實現之一的一個實例。
Hibernate支持三種基本的繼承映射策略: 1.每類層次 2.每個子類表 3.每個具體類 – amitmah
表參照表:https://docs.jboss.org /hibernate/orm/3.5/reference/en-US/html/inheritance.html 我認爲你可以像處理Hibernate中的Abstract類一樣處理接口。 – amitmah