There seems to be a problem using <components> within an 'IN' Expression.
Let's assume the following situation:
We have a class that contains a 'state' component with the properties 'code' and 'subCode'
Code:
<component
name="state"
class="com.xyz.State">
<property
name="code"
type="java.lang.String"
column="STATE_CODE"
length="3"
not-null="true"/>
<property
name="subCode"
type="java.lang.String"
column="SUB_STATE_CODE"
length="3"/>
</component>
I now want to search for objects that match a given component criteria (e.g. objects where code='DFT' and subCode='UDF'). Therefore I use an IN Expression.
Code:
// some code omitted
buffer.append("where state in (:state_list)");
Query query = session.createQuery(buffer.toString());
query.setParameterList("state_list", getStates());
query.list();
private State[] getStates() {
return new State[] { new State("DFT", "UDF") };
}
The generated SQL code has a syntax error, as there are missing parenthesis around the 2-tuple ('DFT', 'UDF').
Code:
where ((this_.STATE_CODE, this_.SUB_STATE_CODE) in ('DFT' , 'UDF'))
When I use more than one components in my IN list
Code:
private State[] getStates() {
return new State[] { new State("FIN", "UDF"), new State("DFT", "UDF") };
}
the syntax is ok, but the order is wrong:
Code:
where ((this_.STATE_CODE, this_.SUB_STATE_CODE) in (('FIN' , 'DFT'), ('UDF' , 'UDF')))
The correct order would be ('FIN', 'UDF') and ('DFT', 'UDF').
Has anybody experienced similar problems? If not I will report it as a BUG.
thx
patric