-->
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: Callind DB2/UDB user defined function
PostPosted: Mon Dec 03, 2007 3:58 am 
Newbie

Joined: Mon Dec 03, 2007 3:40 am
Posts: 5
Hi,

I'm not sure how to call a db2/udb user defined function. Here's the code for the function:
CREATE FUNCTION ABC.getEmployees( departmentid_in INTEGER )
RETURNS TABLE (EMPLOYEEID INTEGER,DEPARTMENTID INTEGER,LASTNAME VARCHAR(40),FIRSTNAME VARCHAR(40),EMPLOYEECODE VARCHAR(10))
------------------------------------------------------------------------
-- SQL UDF (Table)
------------------------------------------------------------------------
F1: BEGIN ATOMIC
RETURN SELECT *
FROM ABC.EMPLOYEE AS EMPLOYEE
WHERE EMPLOYEE.DEPARTMENTID = getEmployees.departmentid_in;
END

The mapping file:
<?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 package="com.abc.test.model">
<!-- <class name="Employee" table="Employee"> -->
<class name="Employee">
<id name="employeeId" column="employeeId">
<generator class="assigned" />
</id>
<many-to-one name="department" column="departmentId" class="Department" cascade="save-update"/>
<property name="lastname" />
<property name="firstname" />
<property name="employeeCode" />
<set name="contactInfo" cascade="save-update">
<key column="employeeId"/>
<one-to-many class="ContactInfo"/>
</set>
</class>
<sql-query name="getEmployees" callable="true">
<return alias="employee" class="Employee" />
{? = call ABC.getEmployees(:departmentId)}
</sql-query>
</hibernate-mapping>

And here is the code:
employeeList = session.getNamedQuery("getEmployees").setParameter("departmentId", departmentId).list();

When running this I get this:
[java] 2007-12-03 09:53:45,634 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: -99999, SQLState: 07001
[java] 2007-12-03 09:53:45,634 ERROR [org.hibernate.util.JDBCExceptionReporter] - [IBM][CLI Driver] CLI0100E Wrong number of parameters. SQLSTATE=07001

If I change the mapping to this:
<sql-query name="getEmployees" callable="true">
<return alias="employee" class="Employee" />
{call ABC.getEmployees(:departmentId)}
</sql-query>

I get this error:
[java] 2007-12-03 09:55:31,164 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: -440, SQLState: 42884
[java] 2007-12-03 09:55:31,164 ERROR [org.hibernate.util.JDBCExceptionReporter] - [IBM][CLI Driver][DB2/6000] SQL0440N No authorized routine named "ABC.GETEMPLOYEES" of type "PROCEDURE" having compatible arguments was found. SQLSTATE=42884

How should I do the mapping / calling code to be able to use the function?

TIA,

ksakke


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.