Lesson - 42 : Hibernate - Call Procedure or Function In Hibernate Using CallableStatement of JDBC
Автор: Sada Learning Hub
Загружено: 2018-06-13
Просмотров: 358
Описание:
Hibernate – Procedure Call Using Callable Statement :
We have two approaches to call procedure or function.
1. If a procedure or a function returns scalar values then it can be called using CallableSatement of jdbc in hibernate.
2. If a procedure or a function returns a cursor object then it can be called using queries concept of hibernate.
Approch-1
If a procedure or a function returns scalar values then it can be called using CallableSatement of jdbc in hibernate.
1. This approach is used when a procedure or function is returning row values or scalar values which means like a number or string or date etc.
2. This approach is added in hibernate from 3.6.5 version onwards.
The following the steps to call a procedure or a function in this approach
1. Create a class byimplementing org.hibernate.jdbc.Work interface.
2. Implement the only one abstract method of work interface called execute().
3. Define the procedure or function call code in execute method.
4. Pass the class object as a parameter to the do work method of session interface.
//step-1
class ProcedureCall implements org.hibernate.jdbc.work
//step2
public void execute(Connection con)throws SQLException
//step3
CallableStatements cstmt = con.preparecall("{call procedure name(?,?,?)}");
cstmt.execute();
//step-4
ProcedureCall pc = new ProcedureCall();
Session.doWork(pc);
//step-1
class ProcedureCall implements org.hibernate.jdbc.work{
//step2
public void execute(Connection con)throws SQLException{
//step3
CallableStatements cstmt = con.preparecall("{call procedure name(?,?,?)}");
cstmt.execute();
}
}
Class Main{
public static void main(String[] args){
ProcedureCall pc = new ProcedureCall();
//step-4
Session.doWork(pc);
}
}
Hibernate Examples Project Github Link : https://github.com/SadaLearningHub1/H...
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: