现在的位置: 首页 > 综合 > 正文

hibernate 开发学习过程中遇到的问题:

2013年04月24日 ⁄ 综合 ⁄ 共 770字 ⁄ 字号 评论关闭

org.hibernate.HibernateException: identifier of an instance of com.soft.sys.model.Org was altered from 1 to 1

看我配置文件:

  <class name="Org" table="t_org">
  <id name="id" column="id" type="int">
   <generator class="increment"></generator>
  </id>

实体文件:

 public class Org {
 private long id;

 

数据类型不一致。如果hibernate在类型转换时提示出错。

 

 

 

org.hibernate.SessionException: Session was already closed

出现这个异常的前提条件:

 我们的事务管理是ThreadLocalSessionContext即在hibernte.cfg.xml配置文件中进行如下配置:

 <property name="current_session_context_class">thread</property>

而当运行此模式后:
   public int save(Org org) {
  Session session = sessionFactory.getCurrentSession();
  Transaction tran = session.beginTransaction();
  tran.begin();
  session.saveOrUpdate(org);
  tran.commit();
 // session.close();
  return 0;
 }

 

执行tran.commit();后将关闭session(); 所以我们在接下来 session.close()调用时多余的了。

抱歉!评论已关闭.