【问题标题】:JPA inheritance Could not determine type forJPA 继承无法确定类型
【发布时间】:2023-03-13 01:50:01
【问题描述】:

我有一个简单的 JPA 映射,但我不断收到 Could not determine type for 异常。省略了 setter 和 getter。

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class SupervisionCommand {

    @Id
    @GeneratedValue
    protected Long id;

}

@Entity
public class MySupervisionCommand extends SupervisionCommand {

}

@Entity
public class Job {

    @Id
    @GeneratedValue
    private Long id;

    private SupervisionCommand command;

}

完整的异常消息:Could not determine type for: com.family.model.SupervisionCommand, at table: job, for columns: [org.hibernate.mapping.Column(command)]

【问题讨论】:

    标签: hibernate jpa


    【解决方案1】:

    您需要在命令上使用 OneToOne 或 ManyToOne 注释(取决于实际基数):

    @ManyToOne
    private SupervisionCommand command;
    

    字段的默认映射是@Column。而且 Hibernate 不知道使用哪种类型的列(varchar?number?)来存储 SuperVisionCommand 实例。如果它实现了 Serializable,Hibernate 会将其序列化并将其存储在 BLOB 列中,但这不是您想要的。

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 2013-12-04
      • 2021-01-06
      • 1970-01-01
      • 2011-06-20
      • 2019-03-22
      • 1970-01-01
      • 2017-11-07
      • 1970-01-01
      相关资源
      最近更新 更多