无参存储过程调用:
List<YourEntity> list = SessionFactory.getCurrentSession.createSQLQuery("{call procedure()}").addEntity(YourEntity.class).list();
有参数存储过程调用:
List<YourEntity> list =
((SQLQuery) this.getCurrentSession().createSQLQuery("{call procedure(?)}").setString(0, yourParam))
.addEntity(YourEntity.class).list();
备注:这里的存储过程是选择一个表的全部字段(即select * from table [where ...]),若是用用select a,b,c,... from table则程序在调用存储过程后应加上.addScalar(
"a"
,Hibernate.STRING)
//列名
.addScalar(
"b"
,Hibernate.STRING)...绑定列名
.addScalar(
"b"
,Hibernate.STRING)...绑定列名