创建了一张Customer表,
创建一个查询的存储过程
CREATE OR REPLACE PROCEDURE getCustomerListIS
select * form CUSTOMER;
END;
配置文件:
<hibernate-mapping>
<class name="com.test.model.Customer" table="CUSTOMER" schema="LIYANBIN">
<id name="id" type="string">
<column name="ID" length="32" />
<generator class="uuid.hex"></generator>
</id>
<property name="name" type="string">
<column name="NAME" length="20" />
</property>
<property name="age" type="string">
<column name="AGE" length="20" />
</property>
</class>
<sql-query name="getCustomerList" callable="true">
<return alias="customer" class="com.test.model.Customer">
<return-property name="id" column="ID"/>
<return-property name="name" column="NAME"/>
<return-property name="age" column="AGE" />
</return>
{call getCustomerList()}
</sql-query>
</hibernate-mapping>
调用类:
public class ProcTest { final public static SessionFactory sf = new Configuration().configure().buildSessionFactory(); /** * @param args */
public static void main(String[] args) throws Exception {
List list = new ProcTest().listCustomer();
}
/**
* 调用存储过程
* */
public List listCustomer(){
Session session = sf.openSession();
//使用存储过程获取数据
Query query = session.getNamedQuery("getCustomerList");
List list = query.list();
// List list = query.list();
return list;
}}
用debug跟了一下,在query.list()处报错。console台的错误是:
java.sql.SQLException: ORA-06550: 第 1 行, 第 7 列:
PLS-00905: 对象 LIYANBIN.GETCUSTOMERLIST 无效
ORA-06550: 第 1 行, 第 7 列:
PL/SQL: Statement ignored
创建一个查询的存储过程
CREATE OR REPLACE PROCEDURE getCustomerListIS
select * form CUSTOMER;
END;
配置文件:
<hibernate-mapping>
<class name="com.test.model.Customer" table="CUSTOMER" schema="LIYANBIN">
<id name="id" type="string">
<column name="ID" length="32" />
<generator class="uuid.hex"></generator>
</id>
<property name="name" type="string">
<column name="NAME" length="20" />
</property>
<property name="age" type="string">
<column name="AGE" length="20" />
</property>
</class>
<sql-query name="getCustomerList" callable="true">
<return alias="customer" class="com.test.model.Customer">
<return-property name="id" column="ID"/>
<return-property name="name" column="NAME"/>
<return-property name="age" column="AGE" />
</return>
{call getCustomerList()}
</sql-query>
</hibernate-mapping>
调用类:
public class ProcTest { final public static SessionFactory sf = new Configuration().configure().buildSessionFactory(); /** * @param args */
public static void main(String[] args) throws Exception {
List list = new ProcTest().listCustomer();
}
/**
* 调用存储过程
* */
public List listCustomer(){
Session session = sf.openSession();
//使用存储过程获取数据
Query query = session.getNamedQuery("getCustomerList");
List list = query.list();
// List list = query.list();
return list;
}}
用debug跟了一下,在query.list()处报错。console台的错误是:
java.sql.SQLException: ORA-06550: 第 1 行, 第 7 列:
PLS-00905: 对象 LIYANBIN.GETCUSTOMERLIST 无效
ORA-06550: 第 1 行, 第 7 列:
PL/SQL: Statement ignored
tx = session.beginTransaction();
Connection con=session.connection();String procedure = "{call batchUpdateStudent(?) }";
CallableStatement cstmt = con.prepareCall(procedure);
cstmt.setInt(1,0); //把年龄参数设为0
cstmt.executeUpdate();
tx.commit();
参照下!
是可以的,我调用存储函数式要得到一个结果集,是不是得在存储过程里定义一个返回值啊?