`
wyhlzxl
  • 浏览: 33921 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类

getSession() or getHibernateTemplate.getSession()?

    博客分类:
  • java
阅读更多
I'm unsure of which of the above to use in our DAOs (which extend HibernateDAOSupport).

The SpringFramework API doc on HibernateTemplate.getSession() is thus:
protected Session getSession()
Return a Session for use by this template.
Returns a new Session in case of alwaysUseNewSession" (using the same JDBC Connection as a transactional Session, if applicable), a pre-bound Session in case of "allowCreate" turned off, and a pre-bound or new Session else (new only if no transactional or otherwise pre-bound Session exists).

The SpringFramework API doc on getSession() is thus:
protected final Session getSession()
   throws DataAccessResourceFailureException,
   IllegalStateException
Get a Hibernate Session, either from the current transaction or a new one. The latter is only allowed if the "allowCreate" setting of this bean's HibernateTemplate is true.

Note that this is not meant to be invoked from HibernateTemplate code but rather just in plain Hibernate code. Either rely on a thread-bound Session (via HibernateInterceptor), or use it in combination with releaseSession.

In general, it is recommended to use HibernateTemplate, either with the provided convenience operations or with a custom HibernateCallback that provides you with a Session to work on. HibernateTemplate will care for all resource management and for proper exception conversion.
分享到:
评论

相关推荐

    request.getSession().doc

    request.getSession().doc

    基于servlet的购物车

    Map, Book> books = (Map, Book>)request.getSession().getServletContext().getAttribute("books"); Book book = books.get(bookid); System.out.println(book); //得到数量 int bookNum = Integer....

    java 同一用户不能同时登陆问题

    if (httpssessionmap.containsKey(userid)&&httpssessionmap.get(userid).equals(event.getSession())) { //userIds.remove(userid); httpssessionmap.remove(userid); if(u!=null && userid....

    关于jsp语法和练习

    request.getSession (). GetAttributes() 答案: A 2. JSP页面需要创建仅在本页面使用的JavaBean的示例,为了完成此功能必须使用jsp:useBean的哪两个属性进行设置?(选择两个选项) A. id B. type C. name D. ...

    网络应用开发 之实现用户登录功能

    验目的 ...HashMap, Integer> map = (HashMap, Integer>) req.getSession().getAttribute("sessionGoods"); 3.写入链接a标签实现对映射的访问 out.write("<a href='./ShowGoods'>继续购买</h1></a>");

    javaweb 做图片水印,水印图片到目录图片上去

    String planeImage = request.getSession().getServletContext().getRealPath("/image").replace("\\", "/")+"/"+"symark.png"; //获取目标图片的路径String targetPic = request.getSession().getServletContext()....

    request.setAttribute 语句前总显示红色感叹号解决办法 HTTP Status 500 -

    type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet execution ...

    hibernate的flush机制

    对hibernate的flush机制有兴趣可以看看

    NHibernate Demo

    5.连接是单线程的,在整个httpRequest处理过程中是公用的,缓存在HttpContext context中 see ref NHibernateHelper.getSession... 6.增加log4net演示,这是一个强大的log记录组件. 這個免費OR Mapping的工具很強大, ...

    基于tomcat的redis配置

    Struts2Utils.getSession().setAttribute(Constants.JCFX_COUNTY, orgList.get(0).get("DISTRICT_CODE") 查看redis数据库中的数据(需要用32位的jdk): java -jar redisclient-win32.x86.1.5.jar 在90.221要查看...

    图片上传并回显插件11111

    .getSession().getServletContext()); MultipartHttpServletRequest multipartRequest = resolver .resolveMultipart(request); MultipartFile file = multipartRequest.getFile("fileList"); 这个file就能...

    前台页面敏感数据传输到后台钱的加密处理(md5加密)

    js:(jsp页面引入md5.js文件) var mobile=$("input[name='mobile']").val(); var hash1=hex_md5(mobile); $("input[name='hidmobile']").val... request.getSession().setAttribute("actList", actList); } }

    关于java应用cookie

    if ("xjg".equals(userName) && "xjg".equals... request.getSession().setAttribute("userName", userName); response.sendRedirect("success.jsp"); }else { response.sendRedirect("fail.jsp"); }

    jsp源码-网络交易系统

    List<Article> alist1 = (List)request.getSession().getAttribute("alist1"); Iterator<Article> in1 = alist1.iterator(); List<Article> alist2 = (List)request.getSession().getAttribute("alist2"); ...

    struts2验证码完整实例

    通过ActionContext.getContext().getSession().put("random", randomNum.getRandomCode())将数字存放到session当中 2、当你登录时候,提交的输入框中的验证码和session中存放的验证码比较,如果一样,则通过,不一样,则...

    jsp 对request.getSession(false)的理解(附程序员常疏忽的一个漏洞)

    【官方解释】 getSession public HttpSession getSession(boolean create) Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a ...

    用SSH+DWR+Oracle做的模拟Google搜索

    Criteria c = super.getSession().createCriteria(Searchinfo.class); //构造函数 or Criterion ce = null ; for(String list:lists){ if(ce==null) ce = Restrictions.like("content", list); else ...

    struts1.2 上传和下载

    struts1.2 的上传和下载, 如果需要得到相对路径, 加一个 String path=request.getSession().getServletContext().getRealPath(); 就行了 ,这个就是comcat下的项目路径。

    java 中 request.getSession(true、false、null)的区别

    主要介绍了java 中 request.getSession(true/false/null)的区别的相关资料,需要的朋友可以参考下

    weChatpay完整版java

    UserAccessToken token = (UserAccessToken) request.getSession().getAttribute("UserAccessToken"); if(null==token){ token = util.getAccessToken3(Constants.APPID, Constants.SECRET,code); ...

Global site tag (gtag.js) - Google Analytics