Reputation: 45682
I've done my code like it had been done it in examples in google. I tried to make one-to-one relationship. But I get error: AnnotationException Referenced property not a (One|Many)ToOne
Question: what is wrong?
@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;
//....
}
Error: java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:src/test/resources/applicationContextTest.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Referenced property not a (One|Many)ToOne: FileContent.fileInfo in mappedBy of FileInfo.fileContent
Caused by: org.hibernate.AnnotationException: Referenced property not a (One|Many)ToOne: FileContent.fileInfo in mappedBy of FileInfo.fileContent
.......
Upvotes: 2
Views: 7603
Reputation: 45682
The answer is to add @OneToOne annotation to FileContent.fileInfo field.
Upvotes: 3