Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Hibernate call stored procedure
PostPosted: Thu Jun 23, 2011 11:24 pm 
Newbie

Joined: Thu Jun 23, 2011 10:48 pm
Posts: 1
I'm trying to call a stored procedure from mysql db.

I'm getting the SEVERE: Can't set IN parameter for return value of stored function call.
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)

in my configuration i have the follow:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

   <class name="Station" table="stations">

      <composite-id name="id"
         class="StationId">
         <key-property name="id" />
         <key-property name="cityId" />
      </composite-id>

      <property name="name">
         <column name="name" length="256" not-null="true" />
      </property>
           <property name="latitude">
         <column name="latitude" not-null="true" />
      </property>

      <property name="longitude">
         <column name="longitude" not-null="true" />
      </property>

   </class>

   <sql-query name="getStationsByRectangleBounds" callable="true">
      <return alias="station" class="Station">
         <return-property name="id">
            <return-column name="id" />
            <return-column name="cityId" />
         </return-property>
         <return-property name="name" column="name" />
         <return-property name="latitude" column="latitude" />
         <return-property name="longitude" column="longitude" />
      </return>
      { ? = call
      getStationsByRectangleBounds(:lowerBoundX,:lowerBoundY,:upperBoundX,:upperBoundY)
      }
   </sql-query>

</hibernate-mapping>


my java code
Code:
Query query = session.getNamedQuery("getStationsByRectangleBounds");
      
query.setParameter("lowerBoundX", new Float(45.531155));
query.setParameter("lowerBoundY", new Float(-73.598183));
query.setParameter("upperBoundX", new Float(45.538300));
query.setParameter("upperBoundY", new Float(-73.582703));
      
List<Station> list = query.list();



the SP:
Code:
CREATE DEFINER=`root`@`localhost` PROCEDURE `getStationsByRectangleBounds`(
    lowerBoundX float,
    lowerBoundY float,
    upperBoundX float,
    upperBoundY float
)
BEGIN
   
SET @rectangle = CONCAT('POLYGON((',
lowerBoundX, ' ', lowerBoundY, ',',
upperBoundX, ' ', lowerBoundY, ',',
upperBoundX, ' ', upperBoundY, ',',
lowerBoundX, ' ', upperBoundY, ',',
lowerBoundX, ' ', lowerBoundY, '))'
);
   
SELECT  id
        , cityId
        , name
        , latitude
        , longitude
FROM stations
WHERE Intersects(location, GeomFromText(@rectangle) );

END



I just started to use Hibernate as my ORM and trying to call the SP to no avail. Really lost. Any help is appreciated.

Thanks,


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.