Hibernate calls Oracle's stored procedures

Source: Internet
Author: User

as we all know, when too much use of database dialect related applications such as stored procedures, triggers, the portability of the application will become worse, especially in hibernate, it is ironic, but what companies in China today will be concerned about the portability of the application?  Now look at the calls to the Oracle stored procedure in hibernate. 1. Plsql Code Create Procedure proc () begin select*From Proctab;end; 1 CREATE PROCEDURE Proc1 (v_no number (4))2begin3 SELECT *From Proc14 where id=V_no;5end; 2.     One way to Hibernate a stored procedure call is to call it through the traditional XML mapping method. -The corresponding relationship between stored procedure mappings and entities in the domain model copy code1 <className= "Com.test.User" table= "Proctab" > 2 <id name= "id" column= "id" > 3 <generatorclass= "Native"/> 4 </id> 5 <property name= "name" column= "name" type= "string"/> 6 <property name= "Age" column= "Age" type= "integer"/> 7 </class> 8 <sql-query name= "GetUser" callable= "true" > 9 <returnalias= "User"class= "Com.test.User" > <return-property name= "id" column= "id"/> <return-property name= "name" column= "name"/> <return-property name= "Age" column= "age"/> </return> 14{call proc ()}</sql-query>Copy Code-Hibernate API calls to the stored procedure copy code1 Session ss=hibernatesessionfactory.getsession ()2 List li=ss.getnamedquery ("GetUser"). List (); 3Ss.close (); 4 5 Session ss=hibernatesessionfactory.getsession ()6 List li=ss.getnamedquery ("GetUser"). List (); 7ss.close (); Copy Code-"The JDBC API calls replication code for stored procedures1 Session session =hibernatesessionfactory.getsession (); 2 Connection conn =session.connection (); 3 ResultSet rs =NULL; 4 CallableStatement call = Conn.preparecall (' {call proc ()} '); 5 rs =Call.executequery (); 6Rs.close (); 7Session.close (); 8 9 Session Session =hibernatesessionfactory.getsession (); Ten Connection conn =session.connection (); ResultSet rs =NULL; CallableStatement call = Conn.preparecall (' {call proc ()} '); rs =Call.executequery (); 14Rs.close (); 15session.close (); Copy Code-"directly using Hibernate createquerysql to call stored procedures to copy code1 Session session =hibernatesessionfactory.getsession (); 2 sqlquery query = Session.createsqlquery ("{Call proc ()}"); 3 List List =query.list (); 4Session.close (); 5 6 Session Session =hibernatesessionfactory.getsession (); 7 sqlquery query = Session.createsqlquery ("{Call proc ()}"); 8 List List =query.list (); 9session.close (); Copy Code-"Copy code to the stored procedure via Hibernate API or Jdbc,api1 CallableStatement call = Conn.preparecall ("{Call proc (?)}"); 2 call.setstring (1, parameters); 3 rs =Call.executequery (); 4 5 CallableStatement call = Conn.preparecall ("{Call proc (?)}"); 6 call.setstring (1, parameters); 7 rs =call.executequery (); Copy Code1 sqlquery query = Session.createsqlquery ("{Call proc (?)}"); 2 query.setstring (0, parameters); 3 List List =query.list ();

Hibernate calls Oracle's stored procedures

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.