开发者

Does a OneToOne entity need to have a ManyToOne relationship to the parent entity

Does a OneToOne entity need to have a ManyToOne relationship to the parent entity or is it not needed?

@Entity 
class Foo {

@OneToOne Bar bar;
}

@Entity 
class Bar {

// Do I need to declare a ManyToOn开发者_开发技巧e declaration to Foo

}


No it is not needed. And it would not be a ManyToOne, it would be a OneToOne... It would be a ManyToOne if the other side was OneToMany.


No; only if your business need it. You have to reduce navigability between POJOs before creating your JPA mapping. It means if a one-way navigation is enough, don't map a two-way relationship.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜