Hi, All
If I use the 'in elements' expression, where the elements of the set have composite ids...
hibernate translates this:
when (m.mctl, m.matp, m.mmdl, '0211') in elements (m.features)
to:
when (machine1_.MCTL , machine1_.MATP , machine1_.MMDL , '0211') in (feature7_.MCTL)
which cause the following exception:
Remote exception occured:
com.ibm.db2.jcc.b.SqlException: An ON clause associated with a JOIN operator or in a MERGE statement is not valid.
It seems as if hibernate uses only the first part of the composite key as use-in-equals. All the other cases it uses the key normally.
In debug mode it seems as if it could find the keys properly:
Quote:
| | | | \-[IN_LIST] SqlNode: 'inList'
| | | | \-[SQL_TOKEN] CollectionFunction: 'feature7_.MCTL' {method=elements,selectColumns=[feature7_.MCTL, feature7_.MATP, feature7_.MMDL, feature7_.DCOD],fromElement=feature7_}
| | | | \-[DOT] DotNode: '.' {propertyName=features,dereferenceType=3,propertyPath=features,path=m.features,tableAlias=feature7_,className=com.x.bean.Feature,classAlias=null}
| | | | +-[ALIAS_REF] IdentNode: '(machine1_.MCTL, machine1_.MATP, machine1_.MMDL)' {alias=m, className=com.x.bean.Machine, tableAlias=machine1_}
| | | | \-[IDENT] IdentNode: 'features' {originalText=features}
My mapping files are:
Code:
<class name="Machine" table="MACHINE">
<composite-id>
<key-property name="Mctl" type="string">
<meta attribute="use-in-equals">true</meta>
<column name="MCTL" length="8" not-null="true"/>
</key-property>
<key-property name="Matp" type="string">
<meta attribute="use-in-equals">true</meta>
<column name="MATP" length="4" not-null="true"/>
</key-property>
<key-property name="Mmdl" type="string">
<meta attribute="use-in-equals">true</meta>
<column name="MMDL" length="4" not-null="true"/>
</key-property>
</composite-id>
....
<set name="features" inverse="true" order-by="DCOD ASC">
<key>
<column name="MCTL" length="8" not-null="true"/>
<column name="MATP" length="4" not-null="true"/>
<column name="MMDL" length="4" not-null="true"/>
</key>
<one-to-many class="Feature" />
</set>
</class>
and:
Code:
<class name="Feature" table="FEATURE">
<composite-id>
<key-many-to-one name="machine" class="Machine">
<meta attribute="use-in-equals">true</meta>
<column name="MCTL" length="8" />
<column name="MATP" length="4" />
<column name="MMDL" length="4" />
</key-many-to-one>
<key-many-to-one name="feature" class="Feature" column="DCOD">
<meta attribute="use-in-equals">true</meta>
</key-many-to-one>
</composite-id>
....
</class>
I use hibernate 3.2.0.cr3.
Does anybody has some tips, what I do wrong?
Thanks:
Bence