关于HibernateDaoSupport中的getHibernateTemplate().execute及executeFind方法

转自:https://blog.csdn.net/angus_17/article/details/8501668

1.

这两个方法都是为了Spring在接管Hibernate之后,可以对HibernateDaoSupport进行灵活的扩展而用的。


二者的主要区别在于,execute返回的是一个Object,而executeFind方法返回的是一个List.


//使用executeFind
protected void deleteByVehicleId(final int vehicleId) throws Exception {
 try {
 this.getHibernateTemplate().executeFind(
 new HibernateCallback() {
 public Object doInHibernate(Session session) throws HibernateException, SQLException {
 Query q = session.createQuery("delete from Vehicle v where v.id=" + vehicleId );
 q.executeUpdate();
 return null;
 }
 });
 } catch (Exception e) {
 throw e;
 }
}


//使用execute
public String updateScreen(final int screenId,final String configStr){
Object o = getHibernateTemplate().execute(new HibernateCallback() {

public Object doInHibernate(Session session) throws HibernateException, SQLException {
SQLQuery query = session.createSQLQuery("update HPS_ParkingLotScreen  set config_Str='" + configStr + "' where id=" +screenId);
try{
int ii = query.executeUpdate();
System.out.println(ii);
return "success";
}catch (Exception e) {
e.printStackTrace();
}
return "fail";
}
});
return o.toString();
}


另外,在new HibernateCallback的内部类的doInHibernate方法中,它的返回值,就是execute或executeFind方法的返回值。

转载于:https://www.cnblogs.com/sharpest/p/7295649.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/280868.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

bootstrap笔记

1.整体排版 <div class"container"><div class"row"><div class"col-md-offset-3 col-md-6"><div class"panel panel-primary"><div class"panel-heading"><h3 class"panel-title&q…

如何将联系人导入Windows联系人文件夹和从中导出联系人

In Windows 7 and 8, there is a Contacts folder in your user directory. This folder can be useful if you have your contacts in a single .vcf file and want to move them into a .csv file for importing into programs like Outlook 2013. 在Windows 7和8中&#xff…

【vue】跟着老马学习vue-数据双向绑定

学习了node.js教程&#xff0c;只能说是有了一定的了解&#xff0c;之前也了解了webpack和es6的核心内容&#xff0c;也看过vue2.0的官网教程&#xff0c;并结合视频看过项目&#xff0c;但是理解和运用仍然存在很多问题&#xff0c;接下来的一段时间&#xff0c;跟着老马学习v…

位运算符2

class TestExer1{public static void main(String[] args){int m 12;int n 5;System.out.println("m:" m " n:" n);//方法一&#xff1a;提供一个临时变量。//int temp m;// m n;// n temp;//System.out.println("m:" m &…

C# 实例解析事件委托之EventHandler

概述事件属于委托的一个子集&#xff0c;像我们平时界面上的鼠标点击按钮后响应事件、事件的发布和订阅等都需要用到委托.通过委托可以很好的实现类之间的解耦好。事件委托EventHandler的函数原型如下&#xff1a;delegate 表示这个个委托&#xff0c;事件委托没有返回值&#…

C# HttpWebRequest post 数据与上传图片到server

主体 Dictionary<string, object> postData new Dictionary<string, object>(); string fileFullPath this.imgFullPath;if (!File.Exists(fileFullPath)){Message(Error, "file not exist: " fileFullPath);goto EndGetPost;}// 先定义一个…

多亏了Google相册,如何一键释放Android手机上的空间

Let’s be real here: modern smartphones have limited storage. While they’re coming with a lot more than they used to, it’s easy to fill 32GB without even realizing it. And with today’s high-end cameras, well, pictures and videos can quickly consume a bi…

用window.location.href实现页面跳转

在写ASP.Net程序的时候&#xff0c;我们经常遇到跳转页面的问题&#xff0c;我们经常使用Response.Redirect &#xff0c;如果客户要在跳转的时候使用提示&#xff0c;这个就不灵光了&#xff0c;如&#xff1a;Response.Write("<script>alert(恭喜您&#xff0c;注…

(一)使用appium之前为什么要安装nodejs???

很多人在刚接触appium自动化时&#xff0c;可能会像我一样&#xff0c;按照教程搭建好环境后&#xff0c;却不知道使用appium之前为什么要用到node.js&#xff0c;nodejs到底和appium是什么关系&#xff0c;对nodejs也不是很了解&#xff0c;接下来我和大家一起理解一下他们之间…

WPF效果第二百零四篇之自定义更新控件

好久没有更新文章,今天抽空来分享一下最近玩耍的自定义控件;里面包含了自定义控件、依赖属性和路由事件;来看看最终实现的效果:1、先来看看前台Xaml布局和绑定:<Style TargetType"{x:Type Cores:UploadWithProgressControl}"><Setter Property"Templat…

u3d 逐个点运动,路径运动。 U3d one by one, path motion.

u3d 逐个点运动&#xff0c;路径运动。 U3d one by one, path motion. 作者&#xff1a;韩梦飞沙 Author&#xff1a;han_meng_fei_sha 邮箱&#xff1a;313134555qq.com E-mail: 313134555 qq.com 逐个点运动&#xff0c;路径运动。 Im going to do some motion and path. 如果…

小米净水器底部漏水_漏水传感器:您可能没有的最容易被忽视的智能家居设备...

小米净水器底部漏水While most smarthome products are aimed at convenience, there’s one smarthome device that’s actually quite useful, possibly saving you headaches and ton of money: the trusty water leak sensor. 虽然大多数智能家居产品都旨在提供便利&#x…

Unity3D笔记十 游戏元素

一、地形 1.1 树元素 1.2 草元素 二、光源 2.1 点光源 点光源&#xff08;Point Light&#xff09;&#xff1a;好像包围在一个类似球形的物体中&#xff0c;读者可将球形理解为点光源的照射范围&#xff0c;就像家里的灯泡可以照亮整个屋子一样。创建点光源的方式为在Hierarch…

BZOJ3511: 土地划分

【传送门&#xff1a;BZOJ3511】 简要题意&#xff1a; 给出n个点&#xff0c;m条边&#xff0c;每个点有A和B两种形态&#xff0c;一开始1为A&#xff0c;n为B 给出VA[i]和VB[i]&#xff0c;表示第i个点选择A和B形态的价值 每条边给出x,y,EA,EB,EC&#xff0c;表示如果x和y都为…

facebook 文本分类_如何禁用和自定义Facebook的通知,文本和电子邮件

facebook 文本分类Facebook is really keen on keeping you on their platform. One of the ways they do that is by sending you notifications whenever the tiniest thing happens. And you won’t just see them on the site—Facebook will also notify you by email, wi…

django06: ORM示例2--uer 与file

存放路径&#xff1a;https://git.lug.ustc.edu.cn/ 笔记 外键与多键 path models.ForeignKey(to"Path")file models.ManyToManyField(to"File") code 处理方式 new_path request.POST.get("new_path",None)models.File.objects.create(…

Error opening terminal: xterm-256color

在使用gdb调试linux内核时&#xff0c;提示如下错误&#xff1a; arm-none-linux-gnueabi-gdb --tui vmlinux Error opening terminal: xterm-256color. 解决办法&#xff1a; 1、 edit your .bash_profile file vim .bash_profile 2、commnet #export TERMxterm-256colo…

四种简单的排序算法

四种简单的排序算法 我觉得如果想成为一名优秀的开发者&#xff0c;不仅要积极学习时下流行的新技术&#xff0c;比如WCF、Asp.Net MVC、AJAX等&#xff0c;熟练应用一些已经比较成熟的技术&#xff0c;比如Asp.Net、WinForm。还应该有着牢固的计算机基础知识&#xff0c;比如数…

Xampp修改默认端口号

为什么80%的码农都做不了架构师&#xff1f;>>> Xampp默认的端口使用如下&#xff1a; Httpd使用80端口 Httpd_ssl使用443端口 Mysql使用3306端口 ftp使用21端口 但是&#xff0c;在如上端口被占用的情况下&#xff0c;我们可以通过修改xampp默认端口的方法&…

为什么csrss进程有三个_什么是客户端服务器运行时进程(csrss.exe),为什么在我的PC上运行它?...

为什么csrss进程有三个If you have a Windows PC, open your Task Manager and you’ll definitely see one or more Client Server Runtime Process (csrss.exe) processes running on your PC. This process is an essential part of Windows. 如果您使用的是Windows PC&…