I have a problem with a collection mapped using hibernate.
The main table is called Node and has an associated table with its attributes identified by key value.
When in try to put and get values everything is perfect and the mapping acts as it is supposed.
The main problem comes when querying through HQL. Then hibernate simply gets mad and mixes key and value.
As you can see in the HQL the expression node1.textAttributes[:value]=:key is the only one that correctly maps the query against the database.
If i use node1.textAttributes[:key]=:value then hibernate maps the key to the value and the value to the key.
Am i turning mad? have i done something wrong?
Get and put operations work perfectly and also the database is correctly update. It is only while querying that hibernate gets confused.
Thx for your help
Hibernate version: 2.*
Mapping documents:
<map
name="textAttributes"
table="NODE_ATTRIBUTES_T"
lazy="true"
sort="unsorted"
inverse="false"
cascade="all-delete-orphan"
>
<key
column="NODE"
>
</key>
<index-many-to-many
class="nf.bsf.beans.common.Name"
column="ATTRIBKEY"
/>
<element
column="ATTRIBVALUE_TEXT"
type="java.lang.String"
not-null="false"
unique="false"
/>
</map>
Code between sessionFactory.openSession() and session.close():
Query query = (Query) pm.createQuery("select node1 from nf.bsf.beans.dss_t.Node node1 where node1.textAttributes[:value]=:key");
Name n1=nameDAO.getName("TEST","A1");
query.setParameter("key",n1);
query.setParameter("value", "aaaa1");
List l=query.list();
Node n=(Node) l.get(0);
System.out.println("map:"+n.getTextAttributes().get(n1));
return l;
The generated SQL (show_sql=true):
select node0_.ID_NODE as ID_NODE, node0_.NAME as NAME, node0_.TYPE as TYPE, node0_.PARENT as PARENT, node0_.ROOT_NODE as ROOT_NODE, node0_.OWNER as OWNER, node0_.CREATION_DATE as CREATION7_, node0_.PROFILE as PROFILE, node0_.MODIFICATION_DATE as MODIFICA9_, node0_.IDX as IDX from NODES_T node0_,NODE_ATTRIBUTES_T textattrib1_ where (textattrib1_.ATTRIBVALUE_TEXT=? and node0_.ID_NODE=textattrib1_.NODE and textattrib1_.ATTRIBKEY = ?)
[junit] 10:35:58,801 DEBUG LongType:46 - binding '1164' to parameter: 2
[junit] 10:35:58,801 DEBUG StringType:46 - binding 'aaaa1' to parameter: 1
|