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.
精彩评论