Beginner |
|
Joined: Thu Jul 08, 2004 8:56 am Posts: 23
|
I need to have a property in a class that is a sum of another property in a set. I've already seen a post here in the forum and basically copied the solution. But the query that I get is wrong. I am going to post the two hbm files here:
<!DOCTYPE hibernate-mapping PUBLIC '-//Hibernate/Hibernate Mapping DTD 2.0//EN' 'http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd'>
<hibernate-mapping default-cascade="all">
<class name="fundarpe.fontesderecurso.FonteDeRecurso" table="fontesderecurso">
<id name="numero" column="numero" type="int" unsaved-value="null">
<generator class="assigned"/>
</id>
<property name="descricao" column="descricao" type="string" length="65" not-null="true"/>
<property name="saldo" column="saldo" type="double" formula="(select sum(Lancamentos.valor) from Lancamentos where (Lancamentos.fonteDeRecurso = id))" />
<set name="lancamentos" cascade="all" inverse="true" lazy="true">
<key column="id"/>
<one-to-many class="fundarpe.fontesderecurso.Lancamento"/>
</set>
<set name="processos" cascade="all" inverse="true" lazy="true">
<key column="id"/>
<one-to-many class="fundarpe.processos.Processo"/>
</set>
</class>
</hibernate-mapping>
----------------------------
<!DOCTYPE hibernate-mapping PUBLIC '-//Hibernate/Hibernate Mapping DTD 2.0//EN' 'http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd'>
<hibernate-mapping default-cascade="all">
<class name="fundarpe.fontesderecurso.Lancamento" table="lancamentos" discriminator-value="L">
<id name="id" column="id" type="long" unsaved-value="null">
<generator class="native"/>
</id>
<discriminator column="tipolancamento" type="character"/>
<property name="descricao" column="descricao" type="string" length="65" not-null="true"/>
<property name="valor" column="valor" type="double" not-null="true"/>
<property name="data" column="data" type="date" not-null="true"/>
<many-to-one name="fonteDeRecurso" class="fundarpe.fontesderecurso.FonteDeRecurso" column="fontederecurso"/>
<subclass name="fundarpe.fontesderecurso.Debito" discriminator-value="D"/>
<subclass name="fundarpe.fontesderecurso.Credito" discriminator-value="C"/>
<subclass name="fundarpe.fontesderecurso.Empenho" discriminator-value="E">
<many-to-one name="processo" class="fundarpe.processos.Processo" column="processo"/>
</subclass>
</class>
</hibernate-mapping>
--------------------------------------
the generated query:
select this.numero as numero0_, this.descricao as descricao0_, (select sum(Lancamentos.valor) from Lancamentos where (Lancamentos.fonteDeRecurso = this.id)) as f0_0_ from fontesderecurso this where 1=1
|
|