【问题标题】:Hibernate Inheritance and Spring BootHibernate 继承和 Spring Boot
【发布时间】:2020-06-09 11:25:30
【问题描述】:

使用 Hibernate 和 Spring Boot 让抽象类 B 继承的抽象类 A 由类 C 继承的正确方法是什么?

@Entity 
@Inheritance 
abstract class A{} 

@Entity
@Inheritance
abstract class B extends A{}

@Entity 
@Inheritance 
final class C entends B{} 

问题是我有一个异常“原因:org.postgresql.util.PSQLException: ERROR: column something(from class A) does not exist”。我的注释错了吗?

【问题讨论】:

  • 你试过@MappedSuperclass吗?此外,实体不应该是final

标签: java hibernate jpa inheritance annotations


【解决方案1】:

据我所知,抽象类不应该是实体。你不能实例化它。试试

@MappedSuperclass
public abstract class A {
}
@MappedSuperclass
public abstract class B extends A {
}
@Entity
public class C extends B {
}

而且,正如他所说,C 类不应该是最终的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-27
    • 1970-01-01
    • 1970-01-01
    • 2017-06-11
    • 2012-06-18
    • 1970-01-01
    • 2020-06-08
    • 2019-04-06
    相关资源
    最近更新 更多