【发布时间】:2013-12-19 07:58:43
【问题描述】:
我尝试有2个表,如下:
MISExercise(表格)
ID 名称 ...
2个
MISInteractiveExercise(表)
ID 名称 ...
1b
它们不能有相同的 id。他们是从同一个基地继承而来的。我的代码是:
@MappedSuperclass
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class MISExerciseBase {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Integer id;
...
}
@Entity
public class MISExercise extends MISExerciseBase{
...
}
@Entity
public class MISInteractiveExercise extends MISExerciseBase{
...
}
不幸的是,我发现 MISExercise 的表和 MISInteractiveExercise 的表可以具有相同的 id。当我用谷歌搜索时,我找到了http://openjpa.208410.n2.nabble.com/same-Id-on-mapped-superclass-td2435374.html。 @Kaayan 似乎有同样的问题。但我无法从该页面获得帮助。
如果我使用@Entity 而不是@MappedSuperclass,似乎会很好。但是为什么,有什么好的方法呢?
【问题讨论】:
标签: hibernate inheritance mappedsuperclass