您的位置:首页 > 其它

hibernate调用存储过程获取数据要点

2017-12-22 11:04 323 查看
无参存储过程调用:
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)...绑定列名

[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: