-->
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.  [ 5 posts ] 
Author Message
 Post subject: one hibernate select generating a lot of sql statements
PostPosted: Thu Apr 21, 2005 12:00 pm 
Regular
Regular

Joined: Fri Jan 28, 2005 3:11 am
Posts: 81
I am very sorry for not posting in the exact forum format, but I am in a major rush to meet a deadline, so I appreciate your understanding.

I am running a following statement in hibernate:
somelist = session.find("from Rfq rfq order by rfq.po.poDate asc where rfq.po.buyerCode='GAK'");

Instead of generating one line for this select I am getting a few dozen of lines of sql from hibernate:

The first one makes sense:

Hibernate: select rfq0_.RFQ_ID as RFQ_ID, rfq0_.ISSUED_BY as ISSUED_BY, rfq0_.RELEASE_DATE as RELEASE_3_, rfq0_.BID_CLOSE_DATE as BID_CLOS4_, rfq0_.TAX_INFORMATION as TAX_INFO5_, rfq0_.FOB as FOB, rfq0_.SPECIAL_INSTRUCTIONS as SPECIAL_7_, rfq0_.RFQ_CONSTANT as RFQ_CONS8_, rfq0_.RFQ_BUYER_CODE as RFQ_BUYE9_, rfq0_.RFQ_BLUES_CODE as RFQ_BLU10_, rfq0_.RFQ_SEQ_REVISION_NUMBER as RFQ_SEQ11_, rfq0_.RFQ_STATUS as RFQ_STATUS, rfq0_.PO_ID as PO_ID, rfq0_.INCREMENTAL_PRICE_QUOTE as INCREME14_ from RFQ_TABLE rfq0_, PO_LIST po1_ where rfq0_.PO_ID=po1_.PO_ID and po1_.SOURCE != 'WEBPO - IDS' AND po1_.active = 1 and ((po1_.BUYER_CODE='GAK' and rfq0_.PO_ID=po1_.PO_ID)) order by po1_.PO_DATE asc

And then a few dozen times of:

Hibernate: select po0_.PO_ID as PO_ID0_, po0_.PARENT_PO_ID as PARENT_P2_0_, po0_.PO_NUMBER as PO_NUMBER0_, po0_.CHANGE_ORDER_SEQ as CHANGE_O4_0_, po0_.SOURCE as SOURCE0_, po0_.PO_DATE as PO_DATE0_, po0_.LOAD_DATE as LOAD_DATE0_, po0_.FILENAME as FILENAME0_, po0_.LOAD_INFO as LOAD_INFO0_, po0_.CREATOR as CREATOR0_, po0_.SUPPLIER_NAME as SUPPLIE11_0_, po0_.SUPPLIER_NUMBER as SUPPLIE12_0_, po0_.BUYER_CODE as BUYER_CODE0_, po0_.BUYER_DEPT as BUYER_DEPT0_, po0_.CONTRACT as CONTRACT0_, po0_.ACTIVE as ACTIVE0_, po0_.PO_TYPE_ID as PO_TYPE_ID0_ from PO_LIST po0_ where po0_.PO_ID=?

Here are the relevant mapping files:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Mon Mar 21 14:36:39 CST 2005 -->
<hibernate-mapping package="com.talisen.lbwebpo.model">

<class name="Po" table="PO_LIST" where="SOURCE != 'WEBPO - IDS' AND active = 1">
<id name="poId" column="PO_ID" type="integer">
<generator class="native"/>
</id>

<property name="parentPoId" column="PARENT_PO_ID" type="integer" />
<property name="poNumber" column="PO_NUMBER" type="string" not-null="true" />
<property name="changeOrderSeq" column="CHANGE_ORDER_SEQ" type="string" />
<property name="source" column="SOURCE" type="string" not-null="true" />
<property name="poDate" column="PO_DATE" type="date" not-null="true" />
<property name="loadDate" column="LOAD_DATE" type="date" not-null="true" />
<property name="filename" column="FILENAME" type="string" not-null="true" />
<property name="loadInfo" column="LOAD_INFO" type="string" />
<property name="creator" column="CREATOR" type="string" />
<property name="supplierName" column="SUPPLIER_NAME" type="string" />
<property name="supplierNumber" column="SUPPLIER_NUMBER" type="integer" />
<property name="buyerCode" column="BUYER_CODE" type="string" />
<property name="buyerDept" column="BUYER_DEPT" type="string" />
<property name="contract" column="CONTRACT" type="string" />
<property name="active" column="ACTIVE" type="byte" not-null="true" />
<property name="poTypeId" column="PO_TYPE_ID" type="integer" not-null="true"/>

</class>

</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Sun Mar 20 20:16:12 CST 2005 -->
<hibernate-mapping package="com.talisen.lbwebpo.model">

<class name="Rfq" table="RFQ_TABLE">
<id name="rfqId" column="RFQ_ID" type="integer">
<generator class="native" />
</id>

<property name="issuedBy" column="ISSUED_BY" type="integer" />
<property name="releaseDate" column="RELEASE_DATE" type="date" />
<property name="bidCloseDate" column="BID_CLOSE_DATE" type="date" />
<property name="taxInformation" column="TAX_INFORMATION" type="string" />
<property name="fob" column="FOB" type="string" />
<property name="specialInstructions" column="SPECIAL_INSTRUCTIONS" type="string" />
<property name="rfqConstant" column="RFQ_CONSTANT" type="string" />
<property name="rfqBuyerCode" column="RFQ_BUYER_CODE" type="string" />
<property name="rfqBluesCode" column="RFQ_BLUES_CODE" type="string" />
<property name="rfqSeqRevisionNumber" column="RFQ_SEQ_REVISION_NUMBER" type="integer" />
<property name="rfqStatus" column="RFQ_STATUS" type="string" />
<property name="poId" column="PO_ID" type="integer"/>
<property name="incrementalPriceQuote" column="INCREMENTAL_PRICE_QUOTE" type="string" />

<many-to-one name="po" column="PO_ID" class="Po" not-null="true" insert="false" update="false"/>

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 1:52 am 
Newbie

Joined: Mon Apr 11, 2005 2:08 pm
Posts: 8
Try the following query:
Code:
from Rfq rfq left outer join fetch rfq.po
order by rfq.po.poDate asc where rfq.po.buyerCode='GAK'


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 5:34 pm 
Regular
Regular

Joined: Fri Jan 28, 2005 3:11 am
Posts: 81
I just tried it but it didn't help. I mean the problem goes away when I set a lazy attribute as in <class name="Po" table="PO_LIST" where="SOURCE != 'WEBPO - IDS' AND active = 1" lazy="true">, but then the problem is that I need those values, since my jsp has references such as <c:out value="${rfq.po.poNumber}"/>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 23, 2005 12:28 am 
Newbie

Joined: Sat Apr 02, 2005 6:12 pm
Posts: 1
Try changing your many-to-one mapping to this:

Code:
<many-to-one name="po" column="PO_ID" class="Po" not-null="true" insert="false" update="false" lazy="false" fetch="join"/>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 4:07 pm 
Regular
Regular

Joined: Fri Jan 28, 2005 3:11 am
Posts: 81
rehdie's solution worked, I just tried wrong. Thanks to both of you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.