-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate collection mapping gone mad!
PostPosted: Wed Feb 16, 2005 6:37 am 
Newbie

Joined: Wed Feb 16, 2005 5:56 am
Posts: 6
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.