相关疑难解决方法(0)

JPA Hibernate一对一的关系

我有一对一的关系,但hibernatetool在生成模式时抱怨.这是一个显示问题的示例:

@Entity
public class Person {
    @Id
    public int id;

    @OneToOne
    public OtherInfo otherInfo;

    rest of attributes ...
}
Run Code Online (Sandbox Code Playgroud)

Person与OtherInfo有一对一的关系:

@Entity
public class OtherInfo {
    @Id
    @OneToOne(mappedBy="otherInfo")
    public Person person;

    rest of attributes ...
}
Run Code Online (Sandbox Code Playgroud)

人拥有OtherInfo的一面.OtherInfo是拥有的一方,因此人们用来mappedBy在Person中指定属性名称"otherInfo".

使用hibernatetool生成数据库模式时出现以下错误:

org.hibernate.MappingException: Could not determine type for: Person, at table: OtherInfo, for columns: [org.hibernate.mapping.Column(person)]
        at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:292)
        at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:175)
        at org.hibernate.cfg.Configuration.iterateGenerators(Configuration.java:743)
        at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:854)
        at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:128)
        ...
Run Code Online (Sandbox Code Playgroud)

知道为什么吗?我做错了什么或者这是一个Hibernate错误?

java hibernate jpa

62
推荐指数
3
解决办法
11万
查看次数

标签 统计

hibernate ×1

java ×1

jpa ×1