gpt4 book ai didi

Hibernate @DiscriminatorColumn 和 @DiscriminatorValue 问题

转载 作者:行者123 更新时间:2023-12-02 23:34:37 25 4
gpt4 key购买 nike

我有这个父类:

@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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com