How are you establishing the association between a and b? I expect the problem is because you are using something like the following code to establish the relationship between a and b.
Code:
A a = new A();
B b = new B();
a.getBs().add(a);
session.save(a);
It is fair enough the you expect this to work but it doesn't. It doesn't work with your setup because when saving or updating hibernate determines whether an assocation exists between a and b by looking at b.getA() not a.getBs(). So in the code above b.getA() will return null, hence hibernate thinks there is no relationship between a and b. (you can read more about why this is the case here:
http://www.hibernate.org/hib_docs/v3/reference/en/html/collections.html#collections-bidirectional)
There are two ways to fix this.
1.
Read section "2.2.5.3.2.1. Bidirectional" of
http://www.hibernate.org/hib_docs/annotations/reference/en/html/entity.html#entity-mapping-association-collections and figure out how to make hibernate use the one-to-many side to drive the assocation instead of the many-to-one side.
2.
Change your code ...
Code:
@ManyToOne
@JoinColumn(name="fk_a_id")
public User getA() {
return a;
}
... to:
Code:
@ManyToOne (cascade = CascadeType.ALL)
@JoinColumn(name="fk_a_id")
public User getA() {
return a;
}
)
Then use something like the following code to establish the relationship between a and b
Code:
A a = new A();
B b = new B();
b.setA(a);
session.save(b);
I hope that helps.