-->
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.  [ 2 posts ] 
Author Message
 Post subject: extra outer-join with compsite-id and saveOrUpdateCopy
PostPosted: Wed Jun 15, 2005 12:41 am 
Newbie

Joined: Thu Jun 02, 2005 5:45 pm
Posts: 3
The issue I am having is that when using composite-id(s) an extra SQL outer-join is performed for each row in a collection during a call to saveOrUpdateCopy versus when not using composite-id(s) and I am trying to determine if this is the nature of the composite-id(s) or something with my mapping?.

See the generated SQL below. The first statement is only generated when composite-id(s) are used and is issued for every row int he collection causing a huge performance hit. When not using composite-id(s) only the 2nd statement is performed with expected performance.

I am not designing the DB and would normally not choose to use composite id(s), but am kind of stuck.



Hibernate version: 2.1

Mapping documents:

<hibernate-mapping>
<class name="com.dm.hibernate.Product_" table="T_PRD">
<id name="productId" type="java.lang.String" column="PRD_ID">
<generator class="assigned"/>
</id>
<property name="sku" type="java.lang.String" column="SKU" length="255"/>
<!-- Associations -->
<set name="attributes" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column="PRD_ID"/>
<one-to-many class="com.dm.hibernate.Attribute_"/>
</set>
</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="com.dm.hibernate.Attribute_" table="T_PRD_ATRBT">
<composite-id>
<key-property name="productId" column="PRD_ID"/>
<key-property name="attributeName" column="ATRBT_NAME"/>
</composite-id>
<property name="attributeValue" type="java.lang.String" column="ATRBT_VALUE" length="1500"/>
<!-- Associations -->
<!-- bi-directional many-to-one association to TEocPrd -->
<many-to-one name="product" class="com.dm.hibernate.Product_" not-null="true" column="PRD_ID" insert="false" update="false"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

session.saveOrUpdateCopy( product );

Name and version of the database you are using:

Oracle 9i

Generated SQL:


when using composite id(s) for every attribute this sql statement is generated, when not using composites hibernate does not generate it
select attribute_0_.PRD_ID as PRD_ID1_, attribute_0_.ATRBT_NAME as ATRBT_NAME1_, attribute_0_.ATRBT_VALUE as ATRBT_VA3_1_, product_1_.PRD_ID as PRD_ID0_ ... from T_PRD_ATRBT attribute_0_ left outer join T_PRD product_1_ on attribute_0_.PRD_ID=product_1_.PRD_ID where attribute_0_.PRD_ID=? and attribute_0_.ATRBT_NAME=?

this statement is generated for both the case of composite-id(s) and no composite-id(s)
select attributes0_.PRD_ID as PRD_ID__, attributes0_.ATRBT_NAME as ATRBT_NAME__, attributes0_.PRD_ID as PRD_ID0_, attributes0_.ATRBT_NAME as ATRBT_NAME0_, attributes0_.ATRBT_VALUE as ATRBT_VA3_0_ from T_PRD_ATRBT attributes0_ where attributes0_.PRD_ID=?

[[/i]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 12:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is the nature of using natural ids in HB3. If you want to avoid this, implement Interceptor.isUnsaved(), just like you used to have to do in HB2.1.


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