我不能在JPA实体中使用 java.util.Optional (jdk8 +)。
@OneToOne(optional = false, mappedBy = "authorId")
private Optional<Author> author;
我得到:
Caused by: org.hibernate.AnnotationException: Unknown mappedBy in:
com.mypackage.Album.author, referenced property unknown: java.util.Optional.authorId
答案 0 :(得分:2)
如果要使用可选选项,请实施getter
方法:
@OneToOne(optional = false, mappedBy = "authorId")
private Author author;
public getAuthor(){
return Optional.ofNullable(author);
}
查看this以获得详细信息。