JPA继承无法确定类型 [英] JPA inheritance Could not determine type for

查看:102
本文介绍了JPA继承无法确定类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的JPA映射,但我一直得到无法确定类型的异常。

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

@Id
@GeneratedValue
保护长ID;

}

@实体
公共类MySupervisionCommand扩展SupervisionCommand {

}

@实体
public class Job {

@Id
@GeneratedValue
private Long id;

私人SupervisionCommand命令;




完整的异常信息:可能不确定类型:com.family.model.SupervisionCommand,在table:job,for columns:[org.hibernate.mapping.Column(command)]



 

@ManyToOne
私人SupervisionCommand命令;

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


I have a simple JPA mapping but I keep getting a Could not determine type for exception. Setters and getters are omitted.

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

}

The full exception message: Could not determine type for: com.family.model.SupervisionCommand, at table: job, for columns: [org.hibernate.mapping.Column(command)]

解决方案

You need a OneToOne or ManyToOne annotation (depending on the actual cardinality) on command:

@ManyToOne
private SupervisionCommand command;

The default mapping for fields is @Column. And Hibernate doesn't know which type of column to use (varchar? number?) to store a SuperVisionCommand instance. If it implemented Serializable, Hibernate would serialize it and store it in a BLOB column, but this is not what you want.

这篇关于JPA继承无法确定类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆