我有这个@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