I have the following 2 entities:
User
CreditCard
User is defined with this mapping:
Code:
<set name="creditCards"
inverse="true"
order-by="creditcardid desc" cascade="save-update, lock">
<key column="username" not-null="true"/>
<one-to-many class="CreditCard"/>
</set>
CreditCard is mapped like this:
Code:
<many-to-one name="member" column="username" not-null="true"/>
A user can have many credit cards. A credit card can only belong to a single User.
At run-time, I load a persistent User, looking it up by primary key.
A new credit card is then added like this:
Code:
user.addCreditCard(creditCard);
In the User class:
Code:
public void addCreditCard(CreditCard creditCard) {
this.getCreditCards().add(creditCard);
creditCard.setMember(this);
}
When the transaction commits, i.e., the one that loaded the User instance, no insert into the credit_cards table occurs. Inspecting the user's creditCards collection from within the debugger during the transaction indicates that it is marked dirty. The user is not modified in any other way.
Can anyone tell me what the reasons might be for the credit card collection not being updated when the transaction commits?
Thanks in advance.