-->
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.  [ 2 posts ] 
Author Message
 Post subject: calling stored function from Hibernate
PostPosted: Thu Feb 14, 2008 10:53 am 
Newbie

Joined: Tue Aug 21, 2007 12:36 am
Posts: 6
Hi,

I need to call a stored function from Hibernate. I am encountering error while doing. Can you please help me?

Hibernate version: Hibernate 3.2.4

Mapping documents:
Code:
<sql-query name="createJob" callable= "true">
   <return-scalar column="JOB_ID" type="long"/>
      { ? = call boom_admin.create_job(?, ?, ?) }
    </sql-query>



Code:
FUNCTION create_job (  p_list_id   IN NUMBER,
                            p_hours     IN NUMBER,
                            p_active    IN CHAR )
    return number
    IS
                           
        p_job_id jobs.job_id%TYPE;
        p_name jobs.name%TYPE;
        p_last_started jobs.last_started%TYPE := NULL;                   
        p_runcount jobs.runcount%TYPE := 0;
        p_expired jobs.expired%TYPE := 'N';
        p_expdate jobs.expdate%TYPE := NULL;
        --p_active jobs.active%TYPE := 'Y';
        p_folder_id jobs.folder_id%TYPE;
        p_startdate jobs.startdate%TYPE;
        p_minutes jobs.minutes%TYPE := 0;
        p_email jobs.email%TYPE := 'hshah@doubleclick.net,jliu@doubleclick.net';
        p_task_id tasks.task_id%TYPE := 1;
        p_step tasks.step%TYPE := 1;
        p_path tasks.path%TYPE := NULL;
        p_command tasks.command%TYPE := '/N';
        p_type number := 2;
        p_type_id number;
        p_machine varchar2(250) := 'dtjobpending';
        p_timeout number := 60;
        p_timeout_adjustment number;
        insert_flag NUMBER;
        v_job_id NUMBER;
    BEGIN
        insert_flag := 1;

        p_name := 'List' || to_char(p_list_id);
        p_type_id := p_list_id;

        SELECT folder_id INTO p_folder_id FROM dt_list_type, dt_user_filters
        WHERE filter_id = p_list_id and list_type_id = id;
       
        IF insert_flag = 1 THEN
            SELECT sysdate - 12/24 INTO p_startdate FROM DUAL;
            SELECT job_id_seq.nextval INTO p_job_id FROM dual;
       
            INSERT INTO jobs(job_id,name,active,folder_id,startdate,hours,minutes,email)
            VALUES
            (p_job_id,p_name,p_active,p_folder_id,p_startdate,p_hours,p_minutes,p_email);

            INSERT INTO tasks(task_id, job_id, step, command, type, type_id,
                              machine, timeout)
            VALUES
            (p_task_id, p_job_id, p_step, p_command, p_type, p_list_id,
            p_machine, p_timeout);
        END IF;       
        return p_job_id;
    END create_job;



Code between sessionFactory.openSession() and session.close():

Code:
Query namedQuery = this.getSession().getNamedQuery("createJob")
      .setLong(0, listId)
      .setLong(1, hours)
      .setCharacter(2, status);
      Long id = (Long)namedQuery.uniqueResult();

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 10g

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
Code:
2008-02-14 20:20:32,911 [main] DEBUG com.mchange.v2.resourcepool.BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool@c00025 [managed: 3, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@1a7f9dc)
2008-02-14 20:20:32,911 [main] DEBUG org.hibernate.SQL - { ? = call boom_admin.create_job(?, ?, ?) }
2008-02-14 20:20:32,911 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
2008-02-14 20:20:32,958 [main] DEBUG org.hibernate.type.LongType - binding '8044' to parameter: 2
2008-02-14 20:20:32,958 [main] DEBUG org.hibernate.type.LongType - binding '24' to parameter: 3
2008-02-14 20:20:32,958 [main] DEBUG org.hibernate.type.CharacterType - binding 'Y' to parameter: 4
2008-02-14 20:20:33,536 [main] DEBUG com.mchange.v2.c3p0.impl.NewPooledConnection - com.mchange.v2.c3p0.impl.NewPooledConnection@127461b handling a throwable.
java.sql.SQLException: ORA-06550: line 1, column 13:
PLS-00382: expression is of wrong type
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
   at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
   at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
   at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
   at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:215)
   at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1119)
   at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1278)
   at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3415)
   at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3520)
   at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:5090)
   at com.mchange.v2.c3p0.impl.NewProxyCallableStatement.execute(NewProxyCallableStatement.java:2966)
   at org.hibernate.dialect.Oracle9Dialect.getResultSet(Oracle9Dialect.java:288)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:193)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1784)
   at org.hibernate.loader.Loader.doQuery(Loader.java:674)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
   at org.hibernate.loader.Loader.doList(Loader.java:2220)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
   at org.hibernate.loader.Loader.list(Loader.java:2099)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
   at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:811)
   at com.doubleclick.dart.boom.dao.impl.UserListDtHibernateDao.createJob(UserListDtHibernateDao.java:184)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
   at com.doubleclick.dart.core.util.profiling.PerformanceMonitorInterceptor.invokeUnderTrace(PerformanceMonitorInterceptor.java:28)
   at org.springframework.aop.interceptor.AbstractTraceInterceptor.invoke(AbstractTraceInterceptor.java:110)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
   at com.doubleclick.dart.boom.util.profiling.MethodTimerInterceptor.invoke(MethodTimerInterceptor.java:30)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy15.createJob(Unknown Source)
   at com.doubleclick.dart.boom.manager.impl.UserListManagerImpl.saveList(UserListManagerImpl.java:98)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
   at com.doubleclick.dart.core.util.profiling.PerformanceMonitorInterceptor.invokeUnderTrace(PerformanceMonitorInterceptor.java:28)
   at org.springframework.aop.interceptor.AbstractTraceInterceptor.invoke(AbstractTraceInterceptor.java:110)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
   at com.doubleclick.dart.boom.util.profiling.MethodTimerInterceptor.invoke(MethodTimerInterceptor.java:30)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy20.saveList(Unknown Source)
   at com.doubleclick.dart.boom.test.manager.UserListManagerTest.testSaveList(UserListManagerTest.java:142)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
   at org.testng.internal.Invoker.invokeMethod(Invoker.java:473)
   at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:567)
   at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:834)
   at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
   at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
   at org.testng.TestRunner.runWorkers(TestRunner.java:689)
   at org.testng.TestRunner.privateRun(TestRunner.java:566)
   at org.testng.TestRunner.run(TestRunner.java:466)
   at org.testng.SuiteRunner.runTest(SuiteRunner.java:301)
   at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:296)
   at org.testng.SuiteRunner.privateRun(SuiteRunner.java:276)
   at org.testng.SuiteRunner.run(SuiteRunner.java:191)
   at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:808)
   at org.testng.TestNG.runSuitesLocally(TestNG.java:776)
   at org.testng.TestNG.run(TestNG.java:701)
   at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
   at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)


Top
 Profile  
 
 Post subject: Check ur Procedure
PostPosted: Thu Feb 14, 2008 4:29 pm 
Newbie

Joined: Thu Feb 14, 2008 1:41 pm
Posts: 14
The error thrown is
Code:
PLS-00382: expression is of wrong type


Refer Oracle for more information, it's not a Hibernate issue. Try this http://www.google.com/search?q=PLS-0038 ... wrong+type


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.