轉載自 這裡
前言 :
In this tutorial, you will learn how to call a store procedure in Hibernate.
問題描述 :
Here’s a MySQL store procedure, which accept a stock code parameter and return the related stock data :
In MySQL, you can simple call it with a call keyword :
說明 Hibernate call store procedure :
In Hibernate, there are three approaches to call a database store procedure.
- Native SQL – createSQLQuery
You can use createSQLQuery() to call a store procedure directly.
- NamedNativeQuery in annotation
Declare your store procedure inside the @NamedNativeQueries annotation.
- sql-query in XML mapping file
Declare your store procedure inside the “sql-query” tag.
前言 :
In this tutorial, you will learn how to call a store procedure in Hibernate.
問題描述 :
Here’s a MySQL store procedure, which accept a stock code parameter and return the related stock data :
In MySQL, you can simple call it with a call keyword :
說明 Hibernate call store procedure :
In Hibernate, there are three approaches to call a database store procedure.
- Native SQL – createSQLQuery
You can use createSQLQuery() to call a store procedure directly.
- NamedNativeQuery in annotation
Declare your store procedure inside the @NamedNativeQueries annotation.
- //Stock.java
- ...
- @NamedNativeQueries({
- @NamedNativeQuery(
- name = "callStockStoreProcedure",
- query = "CALL GetStocks(:stockCode)",
- resultClass = Stock.class
- )
- })
- @Entity
- @Table(name = "stock")
- public class Stock implements java.io.Serializable {
- ...
Declare your store procedure inside the “sql-query” tag.
This message was edited 1 time. Last update was at 29/11/2010 14:33:12
沒有留言:
張貼留言