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.
|