-->
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: projection, group by, not single column
PostPosted: Wed Mar 19, 2008 11:03 am 
Newbie

Joined: Wed Mar 19, 2008 10:13 am
Posts: 1
Hi, I'm new to Hibernate and I've got a problem: I've three table:

Table 1:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 16-lug-2007 17.47.28 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
<class name="it.avvocatura.wrap.Fascicolo" table="FASCICOLO">
<composite-id name="id" class="it.avvocatura.wrap.FascicoloId">
<key-property name="id_pratica" type="big_decimal">
<column name="ID_PRATICA" precision="22" scale="0" />
</key-property>
<key-property name="id_fascicolo" type="big_decimal">
<column name="ID_FASCICOLO" precision="22" scale="0" />
</key-property>
</composite-id>
<property name="data_notifica" type="timestamp">
<column name="DATA_NOTIFICA" length="7" not-null="true" />
</property>
<set name="cittadinos" inverse="true" table="FASCICOLO_CITTADINO">
<key>
<column name="ID_PRATICA" precision="22" scale="0" not-null="true" />
<column name="ID_FASCICOLO" precision="22" scale="0" not-null="true" />
</key>
<many-to-many entity-name="it.avvocatura.wrap.Cittadino">
<column name="ID_CITTADINO" precision="22" scale="0" not-null="true" />
</many-to-many>
</set>
</class>
</hibernate-mapping>

Table 2:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 24-ago-2007 17.36.52 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
<class name="it.avvocatura.wrap.FascicoloCittadino" table="FASCICOLO_CITTADINO">
<composite-id name="id" class="it.avvocatura.wrap.FascicoloCittadinoId">
<key-property name="idcittadino" type="big_decimal">
<column name="ID_CITTADINO" precision="22" scale="0" />
</key-property>
<key-property name="idfascicolo" type="big_decimal">
<column name="ID_FASCICOLO" precision="22" scale="0" />
</key-property>
<key-property name="idpratica" type="big_decimal">
<column name="ID_PRATICA" precision="22" scale="0" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>

Table 3:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 16-lug-2007 17.47.28 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
<class name="it.avvocatura.wrap.Cittadino" table="CITTADINO">
<id name="id_cittadino" type="big_decimal">
<column name="ID_CITTADINO" precision="22" scale="0" />
<generator class="assigned" />
</id>
<property name="cog_rag_soc" type="string">
<column name="COG_RAG_SOC" length="100" not-null="true" />
</property>
<set name="fascicolos" inverse="true" table="FASCICOLO_CITTADINO">
<key>
<column name="ID_CITTADINO" precision="22" scale="0" not-null="true" />
</key>
<many-to-many entity-name="it.avvocatura.wrap.Fascicolo">
<column name="ID_PRATICA" precision="22" scale="0" not-null="true" />
<column name="ID_FASCICOLO" precision="22" scale="0" not-null="true" />
</many-to-many>
</set>
</class>
</hibernate-mapping>


I'd like execute a query that doesn't take all the column and make a group by, something like:

Criteria crit = session.createCriteria(Fascicolo.class);
crit.createAlias("cittadinos", "citt", CriteriaSpecification.LEFT_JOIN);
ProjectionList pl = Projections.projectionList();
pl.add(Projections.groupProperty("citt.cog_rag_soc"));
List result = crit.setProjection(pl).list();

But I get an exception:
org.hibernate.QueryException: property does not map to a single column: cittadinos
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumn(CriteriaQueryTranslator.java:371)
at org.hibernate.criterion.PropertyProjection.toSqlString(PropertyProjection.java:41)
at org.hibernate.criterion.ProjectionList.toSqlString(ProjectionList.java:49)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getSelect(CriteriaQueryTranslator.java:310)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:71)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
.....

Can anyone help me?
Thanks.


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.