-->
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: Criteria projections with many-to-many relation
PostPosted: Wed Jun 27, 2007 2:34 pm 
Newbie

Joined: Wed Jun 27, 2007 2:09 pm
Posts: 2
Hello,

i'm having some problems with Hibernates Criteria.

I have two classes related by an unidirectional many-to-many relation, from MacroTask to InterventionGroup.

My problem is that i can't project the InterventionGroups of the MacroTask with Hibernate Criterias.

Here is the code i use:

Session sess= HibernateUtil.getEsbSessionFactory().getCurrentSession();

Criteria c = sess.createCriteria(MacroTask.class);

c.setProjection(Property.forName("interventionGroups"));

List l = c.list();

System.out.println(l);


The result is
[null, null, null, null, null]


But if i use Hql queries, things work well:

Session sess = HibernateUtil.getEsbSessionFactory().getCurrentSession();

Query c = sess.createQuery("select interventionGroups from MacroTask");

List l = c.list();

System.out.println(l);


The result is this:

[ar.com.telecom.segat.model.InterventionGroup@1546dbc[
id=2
code=INS
description=Instalador
], ar.com.telecom.segat.model.InterventionGroup@1546dbc[
id=2
code=INS
description=Instalador
], ar.com.telecom.segat.model.InterventionGroup@1546dbc[
id=2
code=INS
description=Instalador
], ar.com.telecom.segat.model.InterventionGroup@1546dbc[
id=2
code=INS
description=Instalador
] ]


If i just list all the MacroTasks object with Criterias, the result is correct. If i project, not interventionGroup, but another property the result is right again.

I'll send you the sql query that Hibernate generates when i try to project with criteria:

select this_.ID_MACROTAREA as y0_ from AI_LKP_MACROTAREA this_

and when i try to project with Hql:

select interventi2_.ID_GR_INTERV as ID1_2_, interventi2_.COD_GRP_INTERV as COD2_2_, interventi2_.DES_GRP_INTERV as DES3_2_ from AI_LKP_MACROTAREA macrotask0_ inner join AI_REL_MACRO_GR_INTERV interventi1_ on macrotask0_.ID_MACROTAREA=interventi1_.ID_MACROTAREA inner join AI_LKP_GRUPO_INTERVENCION interventi2_ on interventi1_.ID_GR_INTERV=interventi2_.ID_GR_INTERV

And the mapping file:

<hibernate-mapping>

<class name="ar.com.telecom.segat.model.MacroTask" table="AI_LKP_MACROTAREA">
<id name="id" column="ID_MACROTAREA">
<generator class="native"/>
</id>
<property name="code" column="COD_MACROTAREA" length="10" not-null="true" unique="true"/>
<property name="description" column="DES_MACROTAREA" length="40"/>
<property name="operatorSourceField" column="CAMPO_ORIGEN_TECNICO"/>
<set name="interventionGroups" table="AI_REL_MACRO_GR_INTERV" fetch="join">
<key column="ID_MACROTAREA" not-null="true" />
<many-to-many column="ID_GR_INTERV" class="ar.com.telecom.segat.model.InterventionGroup"/>
</set>
</class>

</hibernate-mapping>




I think there is a bug here but i'd like to hear a more experience user.

Thank you all

Leandro


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.