-->
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.  [ 4 posts ] 
Author Message
 Post subject: How call oracle function using session.createSQLQuery
PostPosted: Thu Jun 18, 2009 12:36 pm 
Newbie

Joined: Thu Jun 18, 2009 12:18 pm
Posts: 4
Hello,

I need call an oracle sql function that has this header:

CREATE OR REPLACE PACKAGE ARMADO.COP IS
FUNCTION FNC_SECUENCIA( NUM_CONCESIONARIA IN NUMBER , NOMBRE_SECUENCIA IN VARCHAR2) RETURN NUMBER ;
END;

I have this in my java code:

try
{
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
session = sessionFactory.openSession();
session.beginTransaction();
int result = session.createSQLQuery("{ ? = call ARMADO.COP.FNC_SECUENCIA(?,?)}")
.setParameter(0,3)
.setParameter(1,"NUM_CORR_VIAJE")
.executeUpdate();
}
catch(Exception ex)
{
logger.error("Error : " + ex);
}

But i get this exception: could not execute native bulk manipulation query.

Anyone has any idea???
Thaks in advance.


Top
 Profile  
 
 Post subject: Re: How call oracle function using session.createSQLQuery
PostPosted: Fri Jun 19, 2009 2:17 am 
Newbie

Joined: Fri Jun 19, 2009 1:57 am
Posts: 2
Hi mtigua

Iam also facing same problem.iam new to hibernate.Will u please give me anu suggestions on Calling a simple function using hibernate.These are my steps i followed if any worng please let me know.

Step 1) Created a simple funtion
CREATE OR REPLACE FUNCTION simple RETURN VARCHAR2 IS
BEGIN
RETURN 'Simple Function';
END simple;

Step 2) In hibernate Mapping File

<hibernate-mapping>
<class name="Writer1" table="WRITER1" >
<id name="id" >
<column name="ID" />
<generator class="increment" />
</id>
<property name="name" >
<column name="NAME" />
</property>

<sql-query name="createJob" callable= "true">
<return-scalar column="PASS" type="String"/>
{ ? = call createJob() }
</sql-query>

</class>

</hibernate-mapping>

Step 3) Im Main Program

Query namedQuery = session.getNamedQuery("createJob");

String Pass = (String)namedQuery.uniqueResult();

System.out.println("Calling Stored Proc "+Pass);


Is any thing worng here,actually iam facing error over here


Top
 Profile  
 
 Post subject: Re: How call oracle function using session.createSQLQuery
PostPosted: Fri Jun 19, 2009 2:20 am 
Newbie

Joined: Fri Jun 19, 2009 1:57 am
Posts: 2
Sorry for wrong printing

Over Hiberbate MappingFile

<sql-query name="createJob" callable= "true">
<return-scalar column="PASS" type="String"/>
{ ? = call simple() } //In the previous one it is CreateJob
</sql-query>


Top
 Profile  
 
 Post subject: Re: How call oracle function using session.createSQLQuery
PostPosted: Sat Jun 20, 2009 7:24 pm 
Newbie

Joined: Sat Jun 20, 2009 7:19 pm
Posts: 1
Try getting the return value using


select FNC_SECUENCIA(myNumber1, 'myString') from dual

Good Luck


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

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.