-->
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: Incorrect Where Clause generate from session cache
PostPosted: Thu Sep 06, 2007 2:45 pm 
Newbie

Joined: Thu Sep 06, 2007 1:30 pm
Posts: 2
We have an instance of Vendor class, that has a collection of Accounts that are lazily loaded. If we get the vendor, then run a query for all Vendors and then access the accounts of the original vendor, Hibernate appends multiple vendor IDs in the where clause, because we ran the all vendors query in between.
The strange thing is it always appends 10 vendor ids whereas we have around 25 vendors in the table. Not sure if it appends same vendor id 10 times or they are 10 different vendors.

We do not want to use session.clear(), since we are in the middle of a transaction. Below are the details.

Code:
Hibernate version: 2.1.7


Mapping documents:
Code:
<class name=".Vendor" dynamic-update="true" optimistic-lock="none" table="TELCO" lazy="true">
        <id name="id">
            <column name="TELCO_ID"/>
            <generator class="HibernateSequenceGenerator"/>
        </id>
<dynamic-component name="values">
<set name="accounts" lazy="true" batch-size="100" cascade="all-delete-orphan" inverse="true">
            <key column="BILLING_TELCO_ID"/>
            <one-to-many class="BillingAccount"/>
        </set>
      </dynamic-component>
    </class>

<class name="BillingAccount" dynamic-update="true" optimistic-lock="none" table="BILLING" lazy="true">
        <id name="id">
            <column name="B_ID"/>
            <generator class="HibernateSequenceGenerator"/>
        </id>
        <many-to-one name="vendor" class="Vendor" column="BILLING_TELCO_ID"/>
      </dynamic-component>
    </class>


Test Program:
Code:
public void testBug()
    {
        //Get single vendor by ID
        Vendor myVendor = Vendor.findByKey(new Long(193));

        //Get all vendors
        ObjectList<Vendor> vendors = Vendor.selectAllVendors().execute();
        for (Vendor vendor : vendors)
        {
         vendor.getLongTelcoName();
        }

        //Now get all accounts for the single vendor, query appends OR clause
        Iterator accountsIterator = myVendor.getAccounts().iterator();
        while (accountsIterator.hasNext())
        {
            BillingAccount account = (BillingAccount) accountsIterator.next();
        }
    }


Query is incorrect:
Code:
<select accounts0_.BILLING_TELCO_ID as BILLING17___, ...
from BILLING accounts0_ where ((accounts0_.BILLING_TELCO_ID=?) or (accounts0_.BILLING_TELCO_ID=?) or (accounts0_.BILLING_TELCO_ID=?) or (accounts0_.BILLING_TELCO_ID=?) or (accounts0_.BILLING_TELCO_ID=?) or (accounts0_.BILLING_TELCO_ID=?) or (accounts0_.BILLING_TELCO_ID=?) or (accounts0_.BILLING_TELCO_ID=?) or (accounts0_.BILLING_TELCO_ID=?) or (accounts0_.BILLING_TELCO_ID=?))>


Thanks in advance,
PL


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 6:29 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
You have configured this behaviour with batch-size.
If the batchsize is 5 and you iterate through a list of vendor and call vendor.getAccounts then all accounts for the current and the next 4 vendors are initialized.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 07, 2007 11:04 am 
Newbie

Joined: Thu Sep 06, 2007 1:30 pm
Posts: 2
Thanks very much Sebastian. That worked.

But we are not iterating through a list of vendors, we are saying getAccounts only on single vendor, so why get accounts of other vendors?

Thanks very much
Padma


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.