浏览 4321 次
锁定老帖子 主题:关于transaction的一个问题:
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2004-02-10
Can't start a cloned connection while in manual transaction mode 不知道原因是什么,请各位帮助解决。 代码如下: public static void directPromulgateFile( String fileid, String actorid, Session session) throws SafeFileException { Transaction tx = null; try { tx = session.beginTransaction(); //修改文件表的状态,将其修改为发布状态 MIFileAudit.updateFileStatus(fileid, "2", session); //添加文件审核历史记录表 //先添加起草记录 MIFileAudit.insertFileAuditHistory( fileid, actorid, "1", "1", session); //添加发布记录 MIFileAudit.insertFileAuditHistory( fileid, actorid, "1", "4", session); //提交 tx.commit(); } catch (Exception e) { System.out.println(e.getMessage()); throw new SafeFileException(); } } public static void updateFileStatus( String fileid, String status, Session session) throws SafeFileException { try { String queryString = "select tb_FL_File from TB_FL_File as tb_FL_File where tb_FL_File.file_id = file_id"; Query query = session.createQuery(queryString); query.setInteger("file_id", Integer.parseInt(fileid)); for (Iterator it = query.iterate(); it.hasNext();) { TB_FL_File tb_FL_File = (TB_FL_File) it.next(); tb_FL_File.setStatus(Integer.valueOf(status)); } //暂时不提交 } catch (Exception e) { System.out.println(e.getMessage()); throw new SafeFileException(); } } public static String insertFileAuditHistory( String fileid, String actorid, String audittype, String auditresult, Session session) throws SafeFileException { try { TB_FL_Audit_History tb_FL_Audit_History = new TB_FL_Audit_History(); tb_FL_Audit_History.setFile_id(Integer.valueOf(fileid)); tb_FL_Audit_History.setActor_id(Integer.valueOf(actorid)); tb_FL_Audit_History.setAudit_type(Integer.valueOf(audittype)); tb_FL_Audit_History.setAudit_result(Integer.valueOf(auditresult)); tb_FL_Audit_History.setAudit_date(new Date()); Integer newId = (Integer) session.save(tb_FL_Audit_History); return String.valueOf(newId); } catch (Exception e) { System.out.println(e.getMessage()); throw new SafeFileException(); } } public static String insertFileAuditManage( String fileid, String parentid, String actorid, String status, String result, Session session) throws SafeFileException { try { TB_FL_Audit_Manage tb_FL_Audit_Manage = new TB_FL_Audit_Manage(); tb_FL_Audit_Manage.setFile_id(Integer.valueOf(fileid)); tb_FL_Audit_Manage.setAumn_parent_id(Integer.valueOf(parentid)); tb_FL_Audit_Manage.setActor_id(Integer.valueOf(actorid)); tb_FL_Audit_Manage.setStatus(Integer.valueOf(status)); tb_FL_Audit_Manage.setResult(Integer.valueOf(result)); Integer newId = (Integer) session.save(tb_FL_Audit_Manage); return String.valueOf(newId); } catch (Exception e) { System.out.println(e.getMessage()); throw new SafeFileException(); } } 而我以前这样使用如果不查询修改就没有问题。一到修改查询就会报错。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2004-02-10
能不能把model层的代码贴出来?
|
|
返回顶楼 | |
发表时间:2004-02-10
public class TB_FL_File { private Integer file_id; private String file_code; private Integer type_id; private Integer scope_id; private String file_name; private String key_word; private String content; private Integer actor_id; private Integer com_id; private Integer dep_id; private Date create_date; private Date effect_date; private Integer status; } xml映射文件: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http//hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="com.lhx.wuhan.safe.mapping.TB_FL_File" table="TB_FL_File"> <id name="file_id" type="java.lang.Integer" unsaved-value="null" > <column name="file_id" sql-type="int" not-null="true"/> <generator class="increment"/> </id> <property name="file_code" type="java.lang.String"> <column name="file_code" sql-type="varchar" not-null="true"/> </property> <property name="type_id" type="java.lang.Integer"> <column name="type_id" sql-type="int" not-null="true"/> </property> <property name="scope_id" type="java.lang.Integer"> <column name="scope_id" sql-type="int" not-null="true"/> </property> <property name="file_name" type="java.lang.String"> <column name="file_name" sql-type="varchar" not-null="true"/> </property> <property name="key_word" type="java.lang.String"> <column name="key_word" sql-type="varchar" not-null="true"/> </property> <property name="content" type="java.lang.String"> <column name="content" sql-type="ntext" not-null="true"/> </property> <property name="actor_id" type="java.lang.Integer"> <column name="actor_id" sql-type="int" not-null="true"/> </property> <property name="com_id" type="java.lang.Integer"> <column name="com_id" sql-type="int" not-null="true"/> </property> <property name="dep_id" type="java.lang.Integer"> <column name="dep_id" sql-type="int" not-null="true"/> </property> <property name="create_date" type="java.util.Date"> <column name="create_date" sql-type="datetime" not-null="true"/> </property> <property name="effect_date" type="java.util.Date"> <column name="effect_date" sql-type="datetime" not-null="true"/> </property> <property name="status" type="java.lang.Integer"> <column name="status" sql-type="int" not-null="true"/> </property> </class> </hibernate-mapping> 我使用的sqlserver2000数据库 |
|
返回顶楼 | |
发表时间:2004-02-10
我也遇到了这个问题,而且我就是用的hibernate reference的第一个tomcat的例子作的,结果就是使用query.iterate()就出这个问题,我换成query.list()后,结果就没这个问题了,不知道什么原因:(
还用插入得数据是乱码,不知道如何解决(只限SQL Server,换成MySQL,没问题) |
|
返回顶楼 | |
发表时间:2004-02-10
因为session关闭就不能Iterator,Iterator不能保留数据.而List可以保存取出来的数据.
|
|
返回顶楼 | |