这种映射是可能的,但不是很方便,因为您必须管理
TranslatableText
TranslatableDescriptionId
):
public class Category implements Serializable {
...
private Long translatableDescriptionId;
@OneToMany
@JoinColumn(name="id", referencedColumnName="TranslatableDescriptionId")
private Set<TranslatableText> translatableText;
...
}
所以,您需要手动分配unique
translatableDescriptionId
可译文本
id
属于
在坚持之前(你不能只添加
进入
Set
--
public class Category {
...
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "targetId")
private TranslationTarget target;
}
public class TranslationTarget {
@Id @GeneratedValue
private Long id;
@OneToMany
@JoinColumn(name = "targetId")
private Set<TranslatableText> texts;
}
-
create table Category (
targetId int,
...);
create table TranslationTargets (
id int primary key
);
create table TranslatableText (
targetId int not null,
lang enum ('NO','EN','FR'),
text mediumtext,
primary key(targetId, lang));