2

I have a procedure like this :

create or replace PROCEDURE Greeting1 IS sqlstmt varchar2(400);
BEGIN
   sqlstmt:= 'select * from Object_set';
   EXECUTE immediate sqlstmt;
END;

I want to execute it in java code like this:

List<String> result = null;
Query query = getEm().unwrap(Session.class).createSQLQuery("CALL Greeting1()");
    if(query.list() != null) {
         result = query.list();
    }
return result;

But it gives error while getting query.list(). Actually it returns null in Query Objects. How should I get the proper result list. Please suggest me.

2 Answers 2

2

I don't really know stored procedure with Oracle but JPA set an interface to execute stored procedure, you should read this: Calling Stored procedure with Hibernate.

This take care of the case where you use IN, OUT and IN OUT parameters, otherwise for stored function you will have to use jdbc API instead.

Hope it helped.

Sign up to request clarification or add additional context in comments.

Comments

0

I guess it's not possible to use the query.list(); method What I usually do when I need to inovke stored procedure in a hibernate+spring environment is something like this:

//sessionFactory objext is autowired in this DAO
Session hibSession = sessionFactory.getCurrentSession();
hibSession.doWork(new Work()
{
    @Override
    public void execute(Connection sqlConnection) throws SQLException
    {
        //Here I call the stored procedure and valorize my java POJOS if needed
    }
});

I hope it's useful

Angelo

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.