-->
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: Problem with query. Please help.
PostPosted: Tue Jun 15, 2004 9:36 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
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)
---------------------------------------------------
MpConsumo
Code:
<?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>


Mp
Code:
<?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.


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.