zoukankan      html  css  js  c++  java
  • hibernate学习手记(2)

    1.javax.persistence.TransactionRequiredException: no transaction is in progress

    出现该问题是我没有开启事务,我是在保存之前调用了doWork方法去设置setAutoCommit为true.

    解决办法:如果是用到了spring只需要加上@Transactional就可以了,如果使用原始的方式需要调用会话的beginTransaction()方法

    2.org.hibernate.HibernateException: No CurrentSessionContext configured!

    出现该问题是我没有再cfg.xml中配置会员的context.在cfg.xml加入 <property name="hibernate.current_session_context_class">thread</property>就没问题。

    hibernate.current_session_context_class 有两个对应的值 

    一个是thread 表示本地事务,一个是jta表示全局事务

    关于本地事务和全局事务的概念,大家可以百度或者看下这个文章 http://blog.csdn.net/sunitjy/article/details/6585301

    3.org.hibernate.exception.GenericJDBCException: could not execute statement 

    Caused by: java.sql.SQLException: Field 'SID' doesn't have a default value

    org.hibernate.AssertionFailure: null id in DBModel.Students entry (don't flush the Session afterQuery an exception occurs)

    出现该问题是因为我把 *.hbm.xml中的id配置项中的 generator 的 class属性配置成了native,而数据库对应的字段没有配置成自动递增。

  • 相关阅读:
    发送短信验证(防刷新)
    JsRender 学习总结
    JsRender (js模板引擎)
    jQuery中ready与load事件的区别
    web端图片文件直传
    2018面对对象_作业三
    2018面对对象_作业二
    2018面对对象_作业一
    2018寒假作业_4(自我总结)
    2018寒假作业_3(电梯版本二)
  • 原文地址:https://www.cnblogs.com/jpwahaha/p/6854813.html
Copyright © 2011-2022 走看看