Either I'm doing something wrong.. or I'm doing something wrong.
here's the picture. I have an
InvoiceItem table and an
Invoice table, parent-child relationship.. no problem yet.
In the InvoiceItem I have 6 many-to-one connections (via IDs) to other tables (Objects), and in
Invoice I also have several.
Code:
<class name="com.tibbett.controlling.hibernate.Invoice" table="invoice">
<id name="invoiceID" column="invoiceid" type="long" unsaved-value="null">
<generator class="sequence">
<param name="sequence">invoice_uid_sequence</param>
</generator>
</id>
<property name="sysdocNumber" column="sysdocnumber" length="10" type="string"/>
<property name="sysdocDate" column="sysdocdate" length="4" type="date"/>
<property name="recordDate" column="recorddate" length="4" type="date"/>
<property name="bookingDate" column="bookingdate" length="4" type="date"/>
<property name="period" column="period" length="4" type="integer"/>
<property name="cancelled" column="cancelled" length="1" type="boolean"/>
<property name="estimate" column="estimate" length="1" type="boolean"/>
<many-to-one name="type" class="com.tibbett.controlling.hibernate.Type" column="typeid"/>
<many-to-one name="currency" class="com.tibbett.controlling.hibernate.Currency" column="currencyid"/>
<many-to-one name="supplier" class="com.tibbett.controlling.hibernate.Supplier" column="supplierid"/>
<many-to-one name="cancelledInvoice" class="com.tibbett.controlling.hibernate.Invoice" column="cancelled_invoiceid"/>
<many-to-one name="legalEntity" class="com.tibbett.controlling.hibernate.LegalEntity" column="legalentityid"/>
<many-to-one name="pillangoPeriod" class="com.tibbett.controlling.hibernate.PillangoPeriod" column="pillangoperiodid"/>
<set name="invoiceItems" cascade="all" inverse="true" lazy="true">
<key column="invoiceid"/>
<one-to-many class="com.tibbett.controlling.hibernate.InvoiceItem"/>
</set>
</class>
and
Code:
<class name="com.tibbett.controlling.hibernate.InvoiceItem" table="invoiceitem">
<id name="itemID" column="itemid" type="long" unsaved-value="null">
<generator class="sequence">
<param name="sequence">invoiceitem_uid_sequence</param>
</generator>
</id>
<property name="text3" column="text3" length="255" type="string"/>
<property name="heading" column="heading" length="255" type="string"/>
<property name="reference" column="reference" length="20" type="string"/>
<property name="internalOrder" column="internalorder" length="255" type="string"/>
<property name="amount" column="amount" length="8" type="double"/>
<property name="amountOc" column="amountoc" length="8" type="double"/>
<property name="cancelled" column="cancelled" length="1" type="boolean"/>
<property name="estimate" column="estimate" length="1" type="boolean"/>
<property name="allocationLevel" column="allocationlevel" length="1" type="integer"/>
<property name="finalLevel" column="final" length="1" type="boolean"/>
<-- some of these also have many-to-one relations to other classes -->
<many-to-one name="profitcenter" class="com.tibbett.controlling.hibernate.Profitcenter" column="profitcenterid"/>
<many-to-one name="costcenter" class="com.tibbett.controlling.hibernate.Costcenter" column="costcenterid"/>
<many-to-one name="ledger" class="com.tibbett.controlling.hibernate.Ledger" column="ledgerid"/>
<many-to-one name="invoice" class="com.tibbett.controlling.hibernate.Invoice" column="invoiceid"/>
<many-to-one name="pillangoPeriod" class="com.tibbett.controlling.hibernate.PillangoPeriod" column="pillangoperiodid"/>
<many-to-one name="allocationParent" class="com.tibbett.controlling.hibernate.InvoiceItem" column="allocation_parentid"/>
<set name="allocationChildren" cascade="all" inverse="true" lazy="true">
<key column="allocationParent"/>
<one-to-many class="com.tibbett.controlling.hibernate.InvoiceItem"/>
</set>
</class>
all works fine, util I need to do a query along the lines of
Code:
from InvoiceItem item
where item.pillangoPeriod.pillangoPeriodID=? and
item.profitcenter.allocatable=true and item.allocationLevel=0 and
item.cancelled = false and item.finalLevel=true
It takes about 80 seconds to return 1200 rows. I assume its going off and initializing pretty much my entire database here and draggin all the objects along with it, since if I only
Code:
select item.itemID
using the same where conditions, it returns in just under 0.8 sec. So the actual search is fine, it chokes when initalizing the objects (I tried getting the IDs first and then loading them.. same thing, the load causes the long delay).
all I can say is.. HELP! anyone have suggestions? I REALLY don't want to go back and hardcode SQL queries for this.. it'll get nasty, and require a huge change in our whole approach to the project.
Yes.. we are hibernate newbies.. this is out first project using it, and so far .. well.. wow :-)
please.. if anyone has suggestions/guidelines/ideas? (I've searched the forum and ..although I may be blind .. haven't found references to this type of problem - are we missing something realy simple here???)
cheers
Ati
email: ati dot rosselet at clarmont dot hu