I have a problem similar to that described here:
I have entity A with primary key A_ID and
B with primary key B_ID and foreign key PK_A_ID to A.
I want to map those two entities half-bidirectionaly(explained later why so):
Code:
@Entity
public class A {
Long id;
Set bs; // 'bs' as plural of 'b'
@Id
@Column(name="A_ID")
public Long getId() { return id; }
@OneToMany
@JoinColumn(name = "PK_A_ID")
public Set getBs() { return bs; }
}
@Entity
public class B {
Long id;
Long aId; // a not mapped as whole entity, only a's id is mapped
@Id
@Column(name="B_ID")
public Long getId() { return id; }
@Column(name="A_ID")
public Long getAId() { return aId; }
}
The problem is: if I create instance of B and add it to 'bs' set of a (that is some instance of A) and then save it ...
Code:
A a = new A(); B b = new B();
a.getBs().add(b);
b.setAId(a.getId());
... I get additional update of B.PK_A_ID. Setting inverse="true", that was possible in non-annotation mapping, would prevent this aditional update.
Why is this type of half-bidirectional mapping good for me: I have one use case where I create Bs and save them
and n use cases where I only need B.aId, not the whole B.a.
So the real question here is: does the ...
emmanuel wrote:
"??????" is not mandatory when to post a question.
the inverse side in the one where mappedBy is, so not having mappedBy on a collection make in inverse=false.
... mean there is no option to specify inverse="true"?