org.hibernate.hql.ast.QuerySyntaxException: table not mapped when table is defined as set

Hi everyone. I am working in a old project.

I know this question has been asked by many users but I think there is something different in this case.

I have the hibernate mapping file where I define this entity:

<class name="ActividadGrupoBolsa" table="ACTIVIDAD_GRUPO_BOLSA">
    <id name="id" type="long">
        <generator class="increment" />
    </id>
    <property name="uid" type="string" not-null="true" unique="true" />
    <property name="cantidad" type="integer" not-null="true" />
    <many-to-one lazy="false" name="actividadModulo" class="ActividadModulo"
        not-null="true" />
        
    <set  name="actividadGrupoBolsaTipoPieza" table="ACTIVIDAD_GRUPO_BOLSA_TIPO_PIEZA" lazy="false" cascade="save-update">
        <key column="actividad_grupo_bolsa" />
        <composite-element class="ActividadGrupoBolsaTipoPieza" >
            <property name="numPiezas" type="integer" not-null="true" />
            <many-to-one name="tipoPieza" lazy="false" class="TipoPieza" not-null="true" />
        </composite-element>
    </set>
</class>

I am trying to execute the next hql query where the following reference appears:

 StringBuffer hql = new StringBuffer();
            hql.append(" SELECT b.nombre, ").append(" COUNT(distinct b.uid),  ")
                    .append(" SUM(a2.numPiezas * a.cantidad * c.valor)")
                    .append(" FROM ActividadGrupoBolsa a, actividadGrupoBolsaTipoPieza a2 ")
                    .append(", ActividadModulo b ").append(", TipoPieza c ");

The errors is:

org.hibernate.hql.ast.QuerySyntaxException: actividadGrupoBolsaTipoPieza is not mapped

I do not understand why the error occurs if I am indicating the name of the table as it appears in the xml file.

Please could someone help me?

Thanks

I think the query should be like this, otherwise it will try to find an entity named actividadGrupoBolsaTipoPieza which you don’t have:

SELECT b.nombre, COUNT(distinct b.uid), SUM(a2.numPiezas * a.cantidad * c.valor)
FROM ActividadGrupoBolsa a JOIN a.actividadGrupoBolsaTipoPieza a2, ActividadModulo b, TipoPieza c

Thanks @beikov. I wanted to treat the relationship as a table and not as a property of the main table.
It works doing it as you say.

I have another question. I’m trying to reference the key activity_group_bag, with the id of the table ActivityGroupBag. For example:

WHERE a.actividadModulo=b.id AND a2.actividadGrupoBolsa=a.id

I am not sure How can I reference , I tried a2.actividadGrupoBolsa, a2.actividad_grupo_bolsa, … but none of them work.

How must I reference it?

Thank you very much again.

You just de-reference the association with the . operator i.e. a.actividadModulo.id = b.id