-->
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: Calling oracle stored procedures - Newbie
PostPosted: Wed Jul 20, 2005 11:13 am 
Newbie

Joined: Wed Jul 20, 2005 11:06 am
Posts: 1
Hi,
I am a newbie in hibernate. I am trying to call an oracle stored procedure in Hibernate. I am getting the following errors. It would be helpful if someone can help me on this.

Thanks,
John

-------- Oracle Stored procedure

FUNCTION updateUser (uname IN VARCHAR2, uid IN NUMBER)
RETURN NUMBER IS
BEGIN

update USERS
set
USERNAME = uname
where
USER_ID = uid;

return SQL%ROWCOUNT;

END updateUser;


---------- Mapping XML

<?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>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="com.ccrt.model.Users" table="USERS" schema="MBARNES">
<id name="UserId" type="java.math.BigDecimal">
<column name="USER_ID" scale="22" precision="0" not-null="true" unique="true" sql-type="NUMBER" />
<generator class="assigned" />
</id>
<many-to-one name="Vendors" class="com.ccrt.model.Vendors">
<column name="VENDOR_ID" scale="22" precision="0" not-null="false" />
</many-to-one>
<property name="Username" type="java.lang.String">
<column name="USERNAME" scale="50" precision="0" not-null="false" sql-type="VARCHAR2" />
</property>
<property name="Password" type="java.lang.String">
<column name="PASSWORD" scale="50" precision="0" not-null="false" sql-type="VARCHAR2" />
</property>
<property name="First" type="java.lang.String">
<column name="FIRST" scale="50" precision="0" not-null="false" sql-type="VARCHAR2" />
</property>
<property name="Last" type="java.lang.String">
<column name="LAST" scale="50" precision="0" not-null="false" sql-type="VARCHAR2" />
</property>
<property name="Email" type="java.lang.String">
<column name="EMAIL" scale="255" precision="0" not-null="false" sql-type="VARCHAR2" />
</property>
<property name="Reset" type="java.lang.Boolean">
<column name="RESET" scale="1" precision="0" not-null="false" sql-type="NUMBER" />
</property>
<set name="SetOfPaymentAccounts">
<key>
<column name="USER_ID" scale="22" precision="0" not-null="false" />
</key>
<one-to-many class="com.ccrt.model.PaymentAccounts" />
</set>
<set name="SetOfSessions">
<key>
<column name="USER_ID" scale="22" precision="0" not-null="false" />
</key>
<one-to-many class="com.ccrt.model.Sessions" />
</set>
<set name="SetOfPayments">
<key>
<column name="USER_ID" scale="22" precision="0" not-null="false" />
</key>
<one-to-many class="com.ccrt.model.Payments" />
</set>
<set name="SetOfCards">
<key>
<column name="USER_ID" scale="22" precision="0" not-null="false" />
</key>
<one-to-many class="com.ccrt.model.Cards" />
</set>

<loader query-ref="updateUser_SP"/>
</class>

<sql-query name="updateUser_SP" callable="true">
{ ? = call updateUser(?) }
</sql-query>

</hibernate-mapping>


------ Code using to call the stored procedure using Hibernate Synchronizer

package com.ccrt;

import org.apache.log4j.Logger;

import com.xx.model.Users;
import com.xx.model.dao.UsersDAO;
import com.xx.model.dao._RootDAO;

public class ShowUsers
{
static Logger logger = Logger.getLogger(ShowUsers.class);
public static void main(String[] args)
{
_RootDAO.initialize();

UsersDAO dao = new UsersDAO();

Users users = dao.findUser("testacct2");
System.out.println(users);
int count = dao.getQuery("updateUser_SP").setString(0,"TTT").setInteger(1,144).executeUpdate();
logger.debug("Users table updated "+count);

_RootDAO.closeCurrentThreadSessions();
}
}

------ Resulting exception details

10:57:06,939 INFO [SessionFactoryImpl] Checking 0 named queries
Hibernate: select this_.USER_ID as USER1_0_, this_.VENDOR_ID as VENDOR2_11_0_, this_.USERNAME as USERNAME11_0_, this_.PASSWORD as PASSWORD11_0_, this_.FIRST as FIRST11_0_, this_.LAST as LAST11_0_, this_.EMAIL as EMAIL11_0_, this_.RESET as RESET11_0_ from MBARNES.USERS this_ where this_.USERNAME=?
java.lang.IllegalArgumentException: No positional parameters in query: updateUser
at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:191)
at org.hibernate.impl.AbstractQueryImpl.setString(AbstractQueryImpl.java:214)
at com.ccrt.ShowUsers.main(ShowUsers.java:20)
User ID : xx
User Name : xx
First Name : xx
Last Name : xx
Password : xx
EMAIL : xx

Exception in thread "main"


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.