3

I'm trying to map a few entities based on the result of an oracle stored function that return a cursor.

My code looks like this:

this.getSession().createSQLQuery("{?=call my_pkg.my_func(:myPar1,:myPar2)}")
                .addEntity(MyTargetClass.class)
                .setParameter("myPar1",par1)
                .setParameter("myPar2",par2)
                .list();

With this code I get the following exception:

java.sql.SQLException: Missing IN or OUT parameter at index:: 3

How can I tell Hibernate that the missing parameter is a cursor?

According to this doc it should be possible, but there's no sample code as to actually invoke the function.

1 Answer 1

2

According to the document that you link to,

To use this query in Hibernate you need to map it via a named query.

So, create a named query, something like this:

<sql-query name="my_pkg_my_func_SP" callable="true">
    <return alias="..." class="MyTargetClass">
        <return-property name="..." column="..."/>
        ...
    </return>
    { ? = call my_pkg.my_func(:myPar1,:myPar2) }
</sql-query>

And call it using something like this:

final List<MyTargetClass> myTargetClassList =
    this.getSession().getNamedQuery("my_pkg_my_func_SP")
    .setParameter("myPar1", par1)
    .setParameter("myPar2", par2)
    .list();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.