|
Okay, I've got a class A which can 0 or more of class B. If I put a @OneToMany in A and a @ManyToOne in B then hibernate creates B as the "owning" side. My problem is that since B is the owning side I can't add to the list of B's in A and then save A and have the associated saved. What is the reason for this? Is there a way to be able to do this without having to create a join table? How can I add them to the collection and have the B's assocation saved without having to do something like B.setA(a) every time?
One solution is to remove the @ManyToOne on B which would persist the collection in A but would also create a join table. Also, I wouldn't be able to write a query like this: "from B b where b.a = :a" which I know I'm going to need to. How have other people gotten around this?
|