Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate无法确定类型_Java_Hibernate - Fatal编程技术网

Java Hibernate无法确定类型

Java Hibernate无法确定类型,java,hibernate,Java,Hibernate,我被这个错误缠住了: org.hibernate.MappingException: Could not determine type for: com.mywebsite.entity.Image, at table: User, for columns: [org.hibernate.mapping.Column(profilePhoto)] 我知道有人问了很多,但我还是坚持这个。它已经试了好几个小时了,我找不到任何有效的东西 以下是我的两门课: @Entity public class

我被这个错误缠住了:

org.hibernate.MappingException: Could not determine type for: com.mywebsite.entity.Image, at table: User, for columns: [org.hibernate.mapping.Column(profilePhoto)]
我知道有人问了很多,但我还是坚持这个。它已经试了好几个小时了,我找不到任何有效的东西

以下是我的两门课:

@Entity
public class Image extends com.mywebsite.entity.Entity{

    //System
    @Id
    @GeneratedValue
    private int id;
    [...]

}


@Entity
public class User extends com.mywebsite.entity.Entity{

    //System
    @Id
    @GeneratedValue
    private int id;
    [...]

    //Data
    private Image profilePhoto;    
    [...]

}
有人能帮我吗

编辑:

试试这个:

@ManyToOne
@JoinColumn(name="profilephoto_id", foreignKey = @ForeignKey(name = "put_name_here_If_You_HaveAForeignKeyConstraint"))    
private Image profilePhoto;
原件:


发件人:

实体的每个非静态非瞬态属性(字段或方法,取决于访问类型)都被视为持久属性,除非将其注释为
@transient


所以Hibernate认为该字段来自数据库,并试图在表中查找该列。要么该列不存在,要么应该存在,在这种情况下,您应该为其创建一个注释映射,如
@column
;或者它在数据库中不存在,也不应该存在,在这种情况下,您应该像文档建议的那样使用
@Transient

这一行前面没有注释吗<代码>私人图像档案照片否我不知道在您提供hbm文件之前是否有一个“私有字符串密码”;因此我如您所说添加了@Column(name=“profilephoto_id”),错误有一点改变:com.mywebsite.entity.Image,在table:User,用于columns:[org.hibernate.mapping.Column(profilephoto_id)]。我的表user中的列名是“profilephoto_id”。我不必添加“foreignKey”,没有它也可以工作。我理解为什么需要joincolumn,但不理解为什么需要manytoone?这是为了声明实体之间的关联。