ObjectDB ObjectDB

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.

edit
delete
#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
edit
delete

Reply

To post on this website please sign in.