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: MySql Stored Procedure Problome
PostPosted: Fri Aug 22, 2008 9:11 pm 
Newbie

Joined: Fri Aug 22, 2008 8:30 pm
Posts: 2
I have problem with mapping store procedure which has a cursor or loop in it. Result list has always only one element. Do I need something else in my configuration in order to make it work?
Database is MySql
Let's say we have this simple stored procedure


DROP PROCEDURE IF EXISTS .abc;
CREATE PROCEDURE abc()
BEGIN
DECLARE a date DEFAULT now();
DECLARE b date DEFAULT Date(DATE_ADD(now(),INTERVAL 4 DAY));
test_while: WHILE (a<b) do
Select a,b;
Set a=Date(DATE_ADD(a,INTERVAL 1 DAY));
END WHILE test_while;

END;

if you map it in hibernate

<sql-query name="test_st_proc" callable="true">
<return-scalar column="a" />
<return-scalar column="b" />
{call abc() }
</sql-query>

and you have a method in dao like this

public void getAbcDates(){

Session session = null;
List<Abc> data = null;
try {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
Query query = session.getNamedQuery("test_st_proc");
query.setResultTransformer(Transformers.aliasToBean(domain.Abc.class));
data = query.list();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
// Actual contact insertion will happen at this step
}
System.out.println("Done List Size:" + data.size());

with JDBC it looks like this
CallableStatement cstmt =conn.prepareCall("call abc()");
boolean hadResults = cstmt .execute();
while (hadResults) {
rs = cs.getResultSet();
data.add(element)
hadResults = cs.getMoreResults();
}

this will return list correctly. Question is how I can make it work with hibernate?


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.