我已经完成了我的代码,就像在谷歌的示例中所做的那样。我试图建立一对一的关系。但我收到错误:AnnotationException Referenced property not a (One|Many)ToOne
问题:怎么了?
@Entity
@Table(name = "filesInfo")
@Inheritance(strategy= InheritanceType.JOINED)
public class FileInfo {
@Id
@SequenceGenerator(name = "file_info_sequence", sequenceName = "sq_file_info")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "file_info_sequence")
@Column(name = "id")
private long fileID;
@JsonIgnore
@OneToOne(mappedBy="fileInfo", cascade=CascadeType.ALL, fetch = FetchType.LAZY)
private FileContent fileContent;
//......
}
@Entity
@Table(name="file_content")
public class FileContent{
@Id
@Column(name="id", unique=true, nullable=false)
@GeneratedValue(generator="gen")
@GenericGenerator(name="gen", strategy="foreign", parameters=@Parameter(name="property", value="fileInfo"))
private long fileID;
@JsonIgnore
@PrimaryKeyJoinColumn
private FileInfo fileInfo;
//....
}
错误: java.lang.IllegalStateException:无法加载 ApplicationContext
原因:org.springframework.beans.factory.BeanCreationException:在 URL [file:src/test/resources/applicationContextTest.xml] 中定义名称为“sessionFactory”的 bean 创建错误:调用 init 方法失败;嵌套异常是 org.hibernate.AnnotationException: Referenced property not a (One|Many)ToOne: FileContent.fileInfo in mappedBy of FileInfo.fileContent
引起: org.hibernate.AnnotationException:引用的属性不是(One|Many)ToOne:FileInfo.fileContent 的 mappedBy 中的 FileContent.fileInfo
…………