JPA继承无法确定类型

时间:2013-08-22 08:56:37

标签: hibernate jpa

我有一个简单的JPA映射,但我不断收到Could not determine type for异常。设置器和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)]

1 个答案:

答案 0 :(得分:10)

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

@ManyToOne
private SupervisionCommand command;

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