您的位置:首页 > 其它

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

2010-09-08 12:12 330 查看
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()调用时多余的了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐