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