Creating Stored Procedure in MYSQL
mysql> DELIMITER //
mysql> create procedure usp_totalEmployeeByDeparment(IN id INT)
-> begin
-> select count(*) as total from employee where dept_id = id;
-> end//
Calling Stored Procedure from mysql command line
MYSQL > CALL usp_totalEmployeeByDepartment(100);
How to call Stored Procedure from hibernate native sql and named query
Native SQL
Query query = session.createSQLQuery(
"CALL usp_totalEmployeeByDeparment(:id)").addEntity(Employee.class).setParameter("id", 7277);
List result = query.list();
for(int i=0; i Employee emp= (Employee)result.get(i);
System.out.println(emp.getDepartment());
}
Named Query
Query query = session.getNamedQuery("usp_totalEmployeeByDeparment").setParameter("id", 7277);
List result = query.list();
for(int i=0; i Employee emp= (Employee )result.get(i);
System.out.println(emp.getDepartment());
}
mysql> DELIMITER //
mysql> create procedure usp_totalEmployeeByDeparment(IN id INT)
-> begin
-> select count(*) as total from employee where dept_id = id;
-> end//
MYSQL > CALL usp_totalEmployeeByDepartment(100);
How to call Stored Procedure from hibernate native sql and named query
Native SQL
Query query = session.createSQLQuery(
"CALL usp_totalEmployeeByDeparment(:id)").addEntity(Employee.class).setParameter("id", 7277);
List result = query.list();
for(int i=0; i
System.out.println(emp.getDepartment());
}
Named Query
Query query = session.getNamedQuery("usp_totalEmployeeByDeparment").setParameter("id", 7277);
List result = query.list();
for(int i=0; i
System.out.println(emp.getDepartment());
}
No comments:
Post a Comment