我有這個@ElementCollection映射,所以我可能會帶來不唯一ID的遺留表的工作:@ElementCollection非集合場
@Entity @Table(...)
@Inheritance(...) @DiscriminatorColumn(...)
class Notification {
@Id
@Column(name="NOTIFICATION_ID")
private BigInteger id;
}
@Entity
@DiscriminatorValue(...)
class SomeNotification extends Notification {
@ElementCollection
@CollectionTable(name="LEGACY_TABLE", [email protected](name="NOTIFICATION_ID"))
private Set<NotificationInfo> someInformations;
}
@Embeddable
class NotificationInfo { // few columns }
我真的不能碰LEGACY_TABLE的結構,現在我面對這樣的:
@Entity
@DiscriminatorValue(...)
class SpecialNotification extends Notification {
// ? This is not a Collection, and it can't be a ManyToOne or OneToOne
// since there is no ID declared on NotificationInfo.
private NotificationInfo verySpecialInformation;
}
我知道這是不是默認支持的,但我很好實現定製,使其與EclipseLink的工作。關鍵是,對於SpecialNotification實例,最多隻能關聯一個NotificationInfo,而不是很多,這就是SomeNotification的情況。
有關我可以在Customizer中開始的地方的任何想法?
謝謝!
我以爲你知道,但是SecondaryTable意味着一個Inner Join。你知道這種關係是可選的。 – 2015-02-06 13:14:27
是的,會使用'inner join'。另外一個選擇是創建一個數據庫視圖,在其中您將「外部連接」可選數據。它甚至可以[支持插入和更新](http://en.wikibooks.org/wiki/Java_Persistence/Advanced_Topics#Views),即使觸發器用於實現它。 – 2015-02-06 13:33:03
如果您使用Hibernate,您可以將其標記爲可選 http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html_single/#mapping-declaration-join – 2015-02-06 14:02:35