【发布时间】:2010-10-21 17:21:08
【问题描述】:
我有一对一的关系,但 hibernatetool 在生成架构时会抱怨。这是一个显示问题的示例:
@Entity
public class Person {
@Id
public int id;
@OneToOne
public OtherInfo otherInfo;
rest of attributes ...
}
Person 与 OtherInfo 是一对一的关系:
@Entity
public class OtherInfo {
@Id
@OneToOne(mappedBy="otherInfo")
public Person person;
rest of attributes ...
}
Person 拥有 OtherInfo 的一方。 OtherInfo 是拥有方,因此 person 使用 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)
...
知道为什么吗?是我做错了什么还是这是一个 Hibernate 错误?
【问题讨论】: