Hello, I have quite irritating problem with onetomany relationship in my app.
Lets say that I have 2 entities: Person and Phone. Both have id's generated by sequence in DB (Postgresql 8.2). Of cource one Person can have many Phones
@ManyToOne @JoinColumn(name="person_id") private Person owner;
If I try to create a new Person, and then assign to it collection of new Phones it fails to execute persist method from entity manager.
Application server log says that I try to execute sql that is saving Phone without Person id. Since foreign key in phone is restricted to be not null it must fail. What do I wrong?
Mike Keith
author
Ranch Hand
Joined: Jul 14, 2005
Posts: 304
posted
0
Do you have the following two annotations on each of the identifier attributes?
Also, make sure that you are either generating the schema, or using a generator that you ahve defined (and including the generator attribute in the @GeneratedValue annotation).