- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个父类:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "BSEntity")
@DiscriminatorColumn(name = "resourceType", discriminatorType = DiscriminatorType.STRING, length = 32)
public abstract class BaseEntity {
和子类
@Entity
@Table(name = "BSCategory")
@DiscriminatorValue("Category")
public class CategoryEntity extends BaseEntity {
但是当我运行该程序时,出现以下错误:
2010-06-03 10:13:54,222 [main] WARN (org.hibernate.util.JDBCExceptionReporter:100) - SQL Error: 1364, SQLState: HY000
2010-06-03 10:13:54,222 [main] ERROR (org.hibernate.util.JDBCExceptionReporter:101) - Field 'resourceType' doesn't have a default value
有什么想法吗?
更新:数据库是MySQL。我还将继承策略更改为 JOINED 而不是 SINGLE_TABLE。帮助
另一个更新:我在某处看到以下帖子,看起来很有趣:http://opensource.atlassian.com/projects/hibernate/browse/ANN-140
新更新:如果我要使用SecondaryTable 方法,我将如何进行?
最终更新:事实证明 @Discriminator 东西在 hibernate 中不能很好地工作。我使用了 @SecondaryTable 方法,它为我解决了这个问题。谢谢大家对我的帮助!
最佳答案
我不是 hibernate 专家,但我想知道您的示例中是否需要 @DiscriminatorColumn
和 @DiscriminatorValue
。您已经在其自己的表中拥有基类,并且我假设所有子类也在其自己的表中?
如果您查看以下链接,您可以看到 InheritanceType.JOINED
未与鉴别器内容一起使用。当您使用 InheritanceType.SINGLE_TABLE
时,将使用鉴别器注释。
http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#d0e1168
关于Hibernate @DiscriminatorColumn 和 @DiscriminatorValue 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2966889/
是否可以为 jpa @DiscriminatorColumn 提供动态值(例如,来自变量)? 例如,有这个实体: @Entity @Table(name = "topic") @Inheritance
你好我在 EJB 中遇到继承问题。之后我向您展示我的代码 @Entity @Inheritance(strategy=InheritanceType.JOINED) @DiscriminatorCol
情况 我有一个带有 DiscriminatorColumn 的实体,配置为单表继承: @Entity @Inheritance(strategy=InheritanceType.SINGLE_TABL
我有这个父类: @Entity @Inheritance(strategy = InheritanceType.JOINED) @Table(name = "BSEntity") @Discrimin
假设我有以下表格: ______________________ | LAWSUIT | |______________________| | ID
我有一个抽象类AbstractTile @Entity @Table(name = "TILES") @Inheritance(strategy = InheritanceType.SINGLE_TA
我正在将 Hibernate 与 JPA 2.1 一起使用,并且我想定义一个具有两个子实体的实体。我的问题是我想定义一个包含两列的 UniqueConstraint:一个 MemberField 和
我有一个遗留的 MS SQL Server 2000 数据库,我正在尝试使用 JPA(准确地说是 EclipseLink)进行映射。 我有一个表“CONTACT1”,其中的文本字段“KEY1”可以是“
我必须维护一些用于管理某些数据库表的 JPA/Hibernate 代码。我有一个这样的类层次结构: @Entity @Table(name="table_name") @Inheritance(str
我目前正在使用 Spring Boot 开发一个项目。 我正在使用的表之一正在使用 DiscriminatorColumn,如下所示: @Entity @Table(name = "document_
我对 id 类中的鉴别器列有继承问题。该表将成功创建,但每个条目在描述符列中获得“0”值。 这是我的基类: @Entity @Inheritance(strategy = InheritanceTyp
我正在 EclipseLink 中寻找一种在同一实体上有两个 @DiscriminatorColumns 的方法 我的 PostreSQL 数据库表是: Dictionary { id, ob
我试图搜索这个错误,但事实上我没有找到任何东西,这让我相信我在做一些愚蠢的事情。我将在下面包含相关代码,但基本上我使用多表继承(或 Class Table Inheritance )并尝试使用 Doc
我正在尝试实现 JPA 实体之间的继承关系。 借用示例: http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual
我在尝试将 实体 对象保留在 Oracle 数据库中时遇到此异常,并且在将 JPA 项目切换到 EclipseLink 2.0 后才开始出现此错误> 来自 Hibernate,并且我正在使用“实体继承
我是一名优秀的程序员,十分优秀!