JiveJdon Community Forums
在线99人   首页   主题总表   培训咨询   精华   查搜   注册    登陆
首页 » 论坛 » 开源项目大家谈
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表
???en_US.forumThreadNext.name??? 下一主题
Go 总共有 3 回复 / 1
 发表新帖子   回复该主题贴
interbase

悄悄话
发表文章: 2
注册时间: 2003年12月30日 16:30
用SQL2000+Tomcat5+Hibernate的时候,出现以下数据库事务错误,是为什么?请看代码 2003年12月30日 16:37 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
标签列表
Could not load object: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.

调用beginTransaction()时错误出现以上错误,是为什么?



package com.hellking.study.hibernate;

import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
import java.util.*;
import java.io.IOException;
import java.io.PrintWriter;

public abstract class HibernateBase
{
protected SessionFactory sessionFactory;//会话工厂,用于创建会话
protected Session session;//hibernate会话
protected Transaction transaction; //hiberante事务

public HibernateBase()throws HibernateException
{
this.initHibernate();
}
// 帮助方法
protected void initHibernate()
throws HibernateException {

// 装载配置,构造SessionFactory对象
sessionFactory = new Configuration().configure().buildSessionFactory();
}

/**
*开始一个Hibernate事务
*/
protected void beginTransaction()
throws HibernateException {

session = sessionFactory.openSession();
transaction = session.beginTransaction();
}

/**
*结束一个Hibernate事务。
*/
protected void endTransaction(boolean commit)
throws HibernateException {

if (commit) {
transaction.commit();
} else {
//如果是只读的操作,不需要commit这个事务。
transaction.rollback();
}
session.close();
}
}


调用时错误:


package com.hellking.study.hibernate;

import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
import java.util.*;

/**
*和course相关的业务逻辑
*/
public class CourseBean extends HibernateBase
{

public CourseBean()throws HibernateException
{
super();
}
/**
*增加一个Course
*/
public void addCourse(Course st)throws HibernateException
{
beginTransaction();
session.save(st);
endTransaction(true);
}

/**
*返回系统中所有的Course
*/
public Iterator getAllCourses()throws HibernateException
{
String queryString = "select courses from Course as courses";
beginTransaction();
Query query = session.createQuery(queryString);
Iterator it= query.iterate();
return it;
}

/**
*删除给定ID的course
*/
public void deleteCourse(String id)throws HibernateException
{
beginTransaction();
Course course=(Course)session.load(Course.class,id);
session.delete(course);
endTransaction(true);
}

/**
*按course的名字进行模糊查找
*/
public Iterator getSomeCourse(String name)throws HibernateException
{
String queryString = "select c from Course as c where c.name like :name" ;
beginTransaction();
Query query = session.createQuery(queryString);
query.setString("name", "%"+name+"%");
Iterator it= query.iterate();
return it;
}

}
Jerry_ypy

悄悄话
发表文章: 1
注册时间: 2004年03月30日 18:21
Re: 用SQL2000+Tomcat5+Hibernate的时候,出现以下数据库事务错误,是为什么?请看代码 2004年03月30日 18:27 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
[Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.

在同一个connection中对一个表先进行了读操作,然后进行写操作,就会出现这样的问题。
easyinfonet

悄悄话
发表文章: 16
注册时间: 2003年07月22日 14:01
Re: 用SQL2000+Tomcat5+Hibernate的时候,出现以下数据库事务错误,是为什么?请看代码 2004年04月01日 14:26 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
jdbc包的问题
如果写一个错误sql(可以激活rollback)
就会报这个错误
flashroom

悄悄话
发表文章: 1
注册时间: 2004年07月27日 09:04
Re: 用SQL2000+Tomcat5+Hibernate的时候,出现以下数据库事务错误,是为什么?请看代码 2004年07月27日 09:07 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
If you pass "SelectMethod=cursor" attribute in connectio url, will allow more than one active statement per connection." jdbc:microsoft:sqlserver://localhost:1433;SelectMethod=cursor;","user","pwd"The reason for this is;When SelectMethod is set to direct, SQL Server does not support multiple active statements on a single connection within a transaction; however, when auto-commit mode is enabled (the default), the Microsoft SQL Server JDBC driver provides the ability to have multiple JDBC statements open on a single JDBC connection. This is done by cloning physical SQL Server connections as needed. To avoid cloning physical SQL Server connections in this circumstance, you should create only one Statement, PreparedStatement, CallableStatement, or DatabaseMetaData object per JDBC Connection object. Be sure to invoke the "close" methods on these objects when you are finished with them, that is, before creating another object of the types described.Sridhar PaladuguMicrosoft Developer SupportJDBC Webdata

======================================
哈哈哈哈,找了好长时间我才找到解决办法,哈哈哈哈哈哈




这个主题有 3 回复 / 1Go
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表    返回页首返回页首
???en_US.forumThreadNext.name??? 下一主题
热点TAG: AOP cache 缓存 DDD EJB 集群 设计模式 Hibernate IOC JiveJdon OO RBAC Seam Spring Struts
google yahoo 新浪ViVi 365Key网摘 天极网摘 CSDN网摘 添加到百度搜藏 POCO网摘 博采网摘
查询本论坛内 回复超过的热门帖子
     回复该主题贴
标题
 
粗体 斜体 下划线 插入图片 插入代码 插入url链接 插入附件
内容
 

手机阅读 add to google add to yahoo
解惑之道在J道 ,打造中国最具影响力的的企业软件社区
OpenSource JIVEJDON v3.0 Powered by JdonFramework Code © 2002-08 jdon.com
anti spam