-->
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: problem when fetching a set - many to many relationship
PostPosted: Wed Jun 03, 2009 9:50 am 
Newbie

Joined: Wed Sep 10, 2008 2:47 pm
Posts: 8
I have this XML mappings:

<hibernate-mapping>
<class entity-name="COLOR" table="COLOR">
<id name="id" type="string" column="id" length="6" />
<property name="position" column="position" not-null="true"
type="short" />
</class>
<class entity-name="OPCUATRO" table="OPCUATRO" dynamic-insert="true"
dynamic-update="true">
<id name="id" type="string" column="id"><generator class="uuid" /></id>
<property name="d1" column="d1" type="string" unique="false" length="30" />
<set name="d3" table="OPCUATRO_d3" fetch="subselect" lazy="false">
<key column="opcuatro_id" />
<many-to-many column="color_id" class="COLOR" lazy="false" fetch="join" />
</set>
</class>
</hibernate-mapping>

When I execute this HQL: "from OPCUATRO" I get the results as in the following example (only one row from the result set is shown):

{id=4028809621a302170121a31ac13c0001, d1=1, d3=[{position=0, id=red, $type$=COLOR}, {position=1, id=blue, $type$=COLOR}], $type$=OPCUATRO}

As you can see, d3 is presented as a Set of entities from the class COLOR (I'm using Map entity mode, not POJOs)

The problem is that when I try to fetch only d1 and d3 with HQL:

"select d1, d3 from OPCUATRO"
I get a SQLGrammarException

If I do:

"select id,d1, elements(d3) from OPCUATRO"
I get
4028809621a302170121a31ac13c0001 1 {position=1, id=blue, $type$=COLOR}
4028809621a302170121a31ac13c0001 1 {position=0, id=red, $type$=COLOR}


What I would like to get is something like:
4028809621a302170121a31ac13c0001 1 [{position=0, id=red, $type$=COLOR}, {position=1, id=blue, $type$=COLOR}]

I mean, I don't know if I am able, via HQL or Criteria, to get d3 as a Set of entities, instead of the cartesian product.

Any help with this would be greatly appreciated.


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.