hibernate procedure

Posted: April 11, 2012 in Hibernate

1. how to create procedure?

A. procedure or function can be applied on tables only.

procedure doesnt return any value.

function return a value.

This example shows the details of a particular employee


Step 1:

We have created a table in sql named as employee using empid and ename.

SQL> create or replace procedure emp_proc(mycur out sys_refcursor,ename in varchar2)as


open mycur for

select * from employee e where e.ename like ename;




Step 2:

in mapping.xml file after </class> tag (like employee.hbm.xml)

<sql-query name=”gopal” callable=”true”>


{ call emp_proc(?,:p1)}


Step 3:

in main class:

public class CallProcedure {

public static void main(String[] args)throws Exception {

Session session=new Configuration().configure().buildSessionFactory().openSession();

Query query=session.getNamedQuery(“gopal”);


List list=query.list();

Iterator iterator=list.iterator();


Employee employee=(Employee)iterator.next();

System.out.println(employee.getEno()+” Name is “+employee.getEname()+” Addr is “+employee.getEaddr());






Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s