- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Hibernate 来保存所有实体都是从基本抽象实体继承的实体。对于所有具体实体,分别有数据库表,带有自动增量主键列。但是使用 GenerationType 作为“AUTO”或“IDENTITY”会出错。我希望代表每个具体实体类的数据库表中的所有记录都应该具有顺序递增的 ID 值。
com.something.SuperClass:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class SuperClass implements Serializable {
private static final long serialVersionUID = -695503064509648117L;
long confirmationCode;
@Id
@GeneratedValue(strategy = GenerationType.AUTO) // Causes exception!!!
public long getConfirmationCode() {
return confirmationCode;
}
public void setConfirmationCode(long confirmationCode) {
this.confirmationCode = confirmationCode;
}
}
@Entity
public abstract class Subclass extends SuperClass {
private static final long serialVersionUID = 8623159397061057722L;
String name;
@Column(nullable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Caused by: org.hibernate.MappingException: Cannot use identity column key
generation with <union-subclass> mapping for: com.something.SuperClass
What's the best and most convenient way for me to generate the ID's? I do not want to change my inheritance strategy.
最佳答案
这里的问题是你混合了“每类表”继承和 GenerationType.Auto。在“每类一张 table ”的策略中,您每个类(class)使用一张 table ,每个 table 都有一个 ID。
我遇到了同样的问题,我通过用 GenerationType.TABLE 替换 @GeneratedValue(strategy = GenerationType.TABLE) 来解决这个问题
最终代码如下所示
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class SuperClass implements Serializable {
private static final long serialVersionUID = -695503064509648117L;
long confirmationCode;
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
public long getConfirmationCode() {
return confirmationCode;
}
public void setConfirmationCode(long confirmationCode) {
this.confirmationCode = confirmationCode;
}
}
关于mysql - 错误 : Cannot use identity column key generation with <union-subclass> ( TABLE_PER_CLASS ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21047167/
在我的应用程序中,我有一个这样的映射 @MappedSuperclass public abstract class Base implements Serializable { @Entity @T
我有两个表:UserExtended 继承自User。但我无法将现有的 User 提升为 UserExtended。 实体: @Entity @Table @Inheritance(strategy
我使用 Hibernate 来持久化继承的对象,但是当我尝试在数据库中持久化对象时收到此消息: org.springframework.dao.InvalidDataAccessResourceUsa
我在 hibernate 方面遇到了一个非常大的问题。 我的继承策略在 eclipselink 作为 jpa 提供程序下完美运行,无论是在 glassfish 还是 jboss 应用程序服务器下,但是
我在 hibernate 中定义了一个树结构。我有一个名为 TreeObject 的抽象元素。一个树对象可以有多个子对象,而只有一个父对象。 我也有这个类的一些实现:表单、类别、问题组和问题。它们都继
这个问题与 this thread 中提到的问题有关。 . 在 MySQL 上使用 JPA 时,我也面临同样的问题。只有当我将生成策略更改为 TABLE 时才能解决它。 但问题是,这个问题背后的原因是
com.something.SuperClass: @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public ab
在 TABLE_PER_CLASS 映射中, 子实体id在所有类型的子实体实例中是否需要唯一 例如: 员工:1,2,3,4,5,6 销售额:1,3,5 开发人员:2,4,6 或者在表中可以是唯一的:
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) 在父类中允许将子实体视为具有与父类相同的信息以及一些属性的表。阅读时这对我来说很好( ht
亲爱的 future 读者:在完成 Sannes answer 之后和他提供的链接,我决定改用序列。较新的 Hibernates 会注意它也适用于 MySQL。 我有一个 abstract 类,其中包
想象一下以下场景,我们使用继承策略 TABLE_PER_CLASS 和 Template 作为父类(super class),而 Product 作为子类。 模板: @Entity @Inherita
我创建了以下场景: @javax.persistence.Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public
我有一个问题,我有一个带有继承 TABLE_PER_CLASS 的基本抽象实体站和三个子表 StationCompany StationAnalysis StationVariant @MappedS
我有一个带有小部件列表的单元格。 Widgets 是一个抽象实体,它用于存储所有 future 实体的公共(public)属性,如按钮、搜索、条件等。请不要考虑 ClassNamed 接口(inter
我正在使用 Hibernate JPA。 假设我有这些类: AbstractPerson |--> ConcreteEmployee |--> ConcreteCustomer 有没有办法让具体的类有
我正在尝试创建一系列对象,这些对象都存储在单独的表中,但是所有这些表上都有一组共同的字段。我希望 Hibernate 对所有这些表进行联合,但不包括父类(super class)作为表。 当我只注释父
我正在尝试在 Hibernate 中实现一个非常简单的继承模型。基本上我有一个可以称为 A 的父类(super class),以及几个继承自 A 的子类。由于我看到的行为对所有这些行为都是相同的,因此
我正在使用 Hibernate 来保存所有实体都是从基本抽象实体继承的实体。对于所有具体实体,分别有数据库表,带有自动增量主键列。但是使用 GenerationType 作为“AUTO”或“IDENT
我尝试有 2 个表,如下所示: MISExercise(表) 身份证名称... 2个 MISInteractiveExercise(表) 身份证名称... 1个 它们必须没有相同的 ID。他们是从同一
我们有 2 个表(一个 Activity 表和一个存档表),它们具有相同的结构(例如 Employee 和 EmployeeArchive )。为了能够利用通用代码为两个表使用结果,我们有一个抽象父类
我是一名优秀的程序员,十分优秀!