[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

05/03/2005 at 03:50PM PDT, ID: 21411639
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4

one hibernate select generating lot of sql statement when using property-ref

Asked by aturetsky in Java Programming Language

Tags: hibernate

(This is in a sense a follow up to my question http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21396914.html#13879622
which was successfully answered. The difference in this case is that the association that's resulting in multiple SQL statements being generated is mapped using a property-ref attribute, and the solution to the question mentioned above does not seem to work in this case.)

Anyhow, here the problem:
I have a class called Po, a member of which has an associated RfqReqs. The latter has a field that keeps track of this relationship. So the Po class mapping has the following line: <one-to-one name="rfqReqs" class="RfqReqs" property-ref="reqPo"/>

while the RfqReqs class mapping has the following line:
<one-to-one name="rfqReqs" class="RfqReqs" property-ref="reqPo"/>

It is mapped that way based on the recommendation on page 221-222 of Hibernate in Action.

I have the RfqReqs class declared as lazy, so that it's not pulled up every time I do a find on a Po class. When I do need it, however, I retrieve it using the "left join fetch po.rfqReqs" as recommended in the answer to my question mentioned above, where, like here, I was looking for a way to prevent multiple SQL statements from being generated.

In this case, however, that solution does not seem to work: I still get multiple SQL statements generated as a result of the RfqReqs association and I suspect it has to do with the fact that I am using the property-ref attribute here.


Please help.


Hibernate version:
2.7

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="com.talisen.lbwebpo.model">
<class name="RfqReqs" table="RFQ_REQS_TABLE" lazy="true">
<id name="rfqReqsId" column="RFQ_REQS_ID" type="integer">
<generator class="native"/>
</id>
<many-to-one name="reqPo" column="REQ_ID" class="Po" unique="true"/>
<many-to-one name="rfq" column="RFQ_ID" class="Rfq"/>
</class>
</hibernate-mapping>


<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="com.talisen.lbwebpo.model">
<class name="Po" table="PO_LIST" where="SOURCE != 'WEBPO - IDS' AND active = 1" lazy="true">
<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"/>
<one-to-one name="rfqReqs" class="RfqReqs" property-ref="reqPo"/>
</class>
</hibernate-mapping>

Data Retrieval Code:
reqListForOneBuyerCode = session.find("from Po po left join fetch po.rfqReqs order by po.poDate asc where po.poTypeId=11 and po.buyerCode='" + buyerCode[i] + "'");
Full stack trace of any exception that occurs:
N/A

Database I'm using:
Oracle 9i

The generated SQL :
Hibernate: select po0_.PO_ID as PO_ID0_, rfqreqs1_.RFQ_REQS_ID as RFQ_REQS1_1_, 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_, rfqreqs1_.REQ_ID as REQ_ID1_, rfqreqs1_.RFQ_ID as RFQ_ID1_ from PO_LIST po0_ left outer join RFQ_REQS_TABLE rfqreqs1_ on po0_.PO_ID=rfqreqs1_.REQ_ID where po0_.SOURCE != 'WEBPO - IDS' AND po0_.active = 1 and ((po0_.PO_TYPE_ID=11 )and(po0_.BUYER_CODE='N1R' )) order by po0_.PO_DATE asc

And then this statement about twenty times:

Hibernate: select rfqreqs0_.RFQ_REQS_ID as RFQ_REQS1_2_, rfqreqs0_.REQ_ID as REQ_ID2_, rfqreqs0_.RFQ_ID as RFQ_ID2_, rfq1_.RFQ_ID as RFQ_ID0_, rfq1_.ISSUED_BY as ISSUED_BY0_, rfq1_.RELEASE_DATE as RELEASE_3_0_, rfq1_.BID_CLOSE_DATE as BID_CLOS4_0_, rfq1_.TAX_INFORMATION as TAX_INFO5_0_, rfq1_.FOB as FOB0_, rfq1_.SPECIAL_INSTRUCTIONS as SPECIAL_7_0_, rfq1_.RFQ_CONSTANT as RFQ_CONS8_0_, rfq1_.RFQ_BUYER_CODE as RFQ_BUYE9_0_, rfq1_.RFQ_BLUES_CODE as RFQ_BLU10_0_, rfq1_.RFQ_SEQ_REVISION_NUMBER as RFQ_SEQ11_0_, rfq1_.RFQ_STATUS as RFQ_STATUS0_, rfq1_.PO_ID as PO_ID0_, rfq1_.STATUS as STATUS0_, rfq1_.INCREMENTAL_PRICE_QUOTE as INCREME15_0_, rfq1_.PROCUREMENT_NOTES as PROCURE16_0_, po2_.PO_ID as PO_ID1_, po2_.PARENT_PO_ID as PARENT_P2_1_, po2_.PO_NUMBER as PO_NUMBER1_, po2_.CHANGE_ORDER_SEQ as CHANGE_O4_1_, po2_.SOURCE as SOURCE1_, po2_.PO_DATE as PO_DATE1_, po2_.LOAD_DATE as LOAD_DATE1_, po2_.FILENAME as FILENAME1_, po2_.LOAD_INFO as LOAD_INFO1_, po2_.CREATOR as CREATOR1_, po2_.SUPPLIER_NAME as SUPPLIE11_1_, po2_.SUPPLIER_NUMBER as SUPPLIE12_1_, po2_.BUYER_CODE as BUYER_CODE1_, po2_.BUYER_DEPT as BUYER_DEPT1_, po2_.CONTRACT as CONTRACT1_, po2_.ACTIVE as ACTIVE1_, po2_.PO_TYPE_ID as PO_TYPE_ID1_ from RFQ_REQS_TABLE rfqreqs0_ left outer join RFQ_TABLE rfq1_ on rfqreqs0_.RFQ_ID=rfq1_.RFQ_ID left outer join PO_LIST po2_ on rfq1_.PO_ID=po2_.PO_ID where rfqreqs0_.REQ_ID=?
[+][-]05/04/05 08:51 PM, ID: 13932897

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: hibernate
Sign Up Now!
Solution Provided By: aozarov
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05/05/05 07:26 AM, ID: 13936166

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/05/05 10:11 AM, ID: 13937908

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/05/05 10:18 AM, ID: 13937980

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/01/05 09:58 AM, ID: 14123528

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/07/05 03:12 PM, ID: 14166463

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/08/05 08:47 AM, ID: 14171821

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/20/05 12:16 PM, ID: 14488264

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/05 06:36 AM, ID: 14660463

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91