-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: before an update it reloads twice
PostPosted: Thu Oct 09, 2008 11:03 am 
Newbie

Joined: Thu Oct 09, 2008 9:01 am
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 11:47 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Customer has a setCustomer()?
Account has a setAccount()?
Account as a private inner class of Customer?

confusing ...

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 3:16 pm 
Newbie

Joined: Thu Oct 09, 2008 9:01 am
Posts: 3
The Customer class has an object Account with its correspondents get and set.
The Account class has an object Customer with its correspondents get and set.

There is no inner class, it is an object.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.