I'm using Hibernate 2.1.3.
I'm trying to execute the following query:
Code:
select m.referencia, sum(mc.quantidade), sum(mc.quantidade * m.custo_unitario)
from mp_consumo mc, mp m
where mc.mp_fk =m.id
and mc.op_fk=1
group by m.referencia
The above code works. I've executed it in the DB console and it gives the desired result:
Code:
referencia: MP1
sum: 15
sum: 346.80
referencia: MP6
sum: 15
sum: 157.65
Now I want to execute it with Hibernate.
The problem is when I execute the code below I get the following error:
Code:
WARN : SQL Error: 0, SQLState: 22003
ERROR: Bad Integer 346.80
WARN : SQL Error: 0, SQLState: 22003
ERROR: Bad Integer 346.80
ERROR: Could not execute query
org.postgresql.util.PSQLException: Bad Integer 346.80
at org.postgresql.jdbc1.AbstractJdbc1ResultSet.toInt(AbstractJdbc1ResultSet.java:857)
at org.postgresql.jdbc1.AbstractJdbc1ResultSet.getInt(AbstractJdbc1ResultSet.java:282)
( ... )
-----------------
Method code
-----------------
Code:
( ... )
res = session.find("select m.referencia, sum(mc.quantidade), sum(mc.quantidade * m.custoUnitario) " +
"from vo.MpConsumo mc join mc.mp m where mc.op = ? group by m.referencia",
op_id, Hibernate.LONG);
( ... )
---------------------------------------------------
Mapping files (generated with Middlegen)
---------------------------------------------------
MpConsumoCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="vo.MpConsumo"
table="mp_consumo"
>
<id
name="id"
type="long"
column="id"
>
<generator class="sequence">
<param name="sequence">mp_consumo_seq</param>
</generator>
</id>
<property
name="quantidade"
type="int"
column="quantidade"
length="4"
/>
<!-- associations -->
<!-- bi-directional many-to-one association to Mp -->
<many-to-one
name="mp"
class="vo.Mp"
not-null="true"
>
<column name="mp_fk" />
</many-to-one>
<!-- bi-directional many-to-one association to Op -->
<many-to-one
name="op"
class="vo.Op"
not-null="true"
>
<column name="op_fk" />
</many-to-one>
</class>
</hibernate-mapping>
MpCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="vo.Mp"
table="mp"
>
<id
name="id"
type="long"
column="id"
>
<generator class="sequence">
<param name="sequence">mp_seq</param>
</generator>
</id>
<property
name="referencia"
type="java.lang.String"
column="referencia"
not-null="true"
length="-1"
/>
<property
name="custoUnitario"
type="java.math.BigDecimal"
column="custo_unitario"
not-null="true"
length="10"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to MpConsumo -->
<set
name="mpConsumos"
lazy="true"
inverse="true"
>
<key>
<column name="mp_fk" />
</key>
<one-to-many
class="vo.MpConsumo"
/>
</set>
</class>
</hibernate-mapping>
Need help please.