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]
|