Hello,
I have a bidirectional association 1:1 between two classes: Customer and Account. Customer is the principal class but it is not the proprietary of the relationship.
Here you can see the partial mappings with annotations:
Code:
public class Account {
...
private Customer customer;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "customers_id")
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
...
}
Code:
public class Customer{
...
private Account account;
@OneToOne(mappedBy = "customer", optional = true)
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
...
}
I'm using hibernate in a web application and everything works fine but there is a strange behaviour when I try to save the object.
Just before sending the update SQL to the DB, it refreshs the Customer object (
one select) and the Account object (
twice the same select).
Why the account object is loaded twice?
Why Customer and Account are not loaded in only 'select' when it behaviours like that when customerDao.get(id) is called?
Is there a way to avoid these three selects?
I guess I'm missing something, can you help me?
Thanks in advance,
Pablo