Java JPA @OneToMany needed to reciprocate @ManyToOne?
Is it a necessary or a good idea to have a reciprocal @OneToMany for the @ManyToOne?
No, it's not mandatory at all, it's a pure design decision. The whole question is... Do you want this (i.e. an uni-directional association):
Or this (i.e. a bi-directional association):
If you don't need to get Bs from A, then you can skip the bs
attribute and the OneToMany
on A side.
If I make the design decision to leave out the @OneToMany annotated attribute now, will come back to bite me further down.
No, and you can add it later if you discover that you need it.
They are optional. There is no need to add them to your model if you don't want to use them.
I'd sugguest to avoid the reverse mapping at all because such collections may become quite large and most persistance layers don't handle these very good. In many cases you'd have to deal with add/remove of already loaded/managed entities related to these collections yourself. So only add those if they really make things easier for you.