开发者

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

开发者 https://www.devze.com 2023-04-04 10:52 出处:网络
Does a OneToOne entity need to have a ManyToOne relationship to the parent entity or is it not needed?

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

精彩评论

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