我有这个代码
private PostsContentsEntity contentsEntity;
@OneToOne( targetEntity = PostsContentsEntity.class)
@JoinColumn(name = "PostId",referencedColumnName = "PostId", insertable = false, updatable = false)
public PostsContentsEntity getContentsEntity() {
return this.contentsEntity;
}
public void setContentsEntity(PostsContentsEntity contentsEntity) {
this.contentsEntity = contentsEntity;
}
在数据库发布表上
PostId UserId PostTime
7 3 2018-02-27 02:52:21
8 3 2018-02-27 02:52:38
9 3 2018-02-27 02:52:57
10 3 2018-02-27 02:53:52
11 3 2018-02-27 02:54:01
发布内容表
PostContentId PostId Content MediaUrl ContentType
1 7 text post noMedia 1
2 8 photo post image/TueFeb27025238MST2018_1519725158056.jpg 2
3 9 video post video/TueFeb27025257MST2018_1519725177971.mp4 3
4 10 text post noMedia 1
5 11 photo post image/TueFeb27025401MST2018_1519725241249.jpg 2
问题是当PostId
on post table
= PostContentId
onpost content table
它成功返回数据
但如果它不等于PostContentId
返回NullPointerException
我加入@JoinColumn(name = "PostId",referencedColumnName = "PostId")
加入PostId
不是PostContentId
但同样的问题!