Home » Support » Forum » OneToMany Bidirectional Relationship Problem

OneToMany Bidirectional Relationship Problem

#1

Hi,

I'm pretty certain I'm doing something stupid. I've read everything I can find on OneToMany in the forum and in the JPA docs, but I can't get it to work with 2.4.0_04. I've attached a testcase.

I want the owning object present in the child, (in the example, Team to be in Player).

Thanks

Paul.

#2

The application has to update both sides of a bidirectional relationship.

Your test passes after fixing the addPlayer method:

public void addPlayer(Player player) {
    this.squad.add(player);
    player.team = this;
}

Practically, updating the owner side only is usually sufficient. But in your test only the mapped by side is being updated, and that is not expected to work.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login