用了Spring的话?将finally去掉试一下?

解决方案 »

  1.   

    用了Spring的话?将finally去掉试一下?
      

  2.   

    Initializing connection provider: org.hibernate.connection.C3P0ConnectionProvider
    C3P0 using driver: com.microsoft.jdbc.sqlserver.SQLServerDriver at URL: jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=yt
    Connection properties: {user=sa, password=****}
    autocommit mode: false
    MLog clients using java 1.4+ standard logging.
    在服务器启动的时候,为什么还有autocommit mode: false这句呢?
      

  3.   

    记得大小写有区别的
    jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=yt;SelectMethod=cursor; 
      

  4.   

    sqlServer不能配置手动式事物,应该是配置transaction 时错了
      

  5.   


    请问,这个怎么说呢?配置transaction 为什么会错了,为什么第一次又成功了?
      

  6.   

    不会吧,hibernate官网上都是这么解释的:
    Hibernate doesn't work with my MS SQL 2000 JDBC driver?(Glen Stampoultzis)If you're using Hibernate with the Microsoft SQL Server 2000 JDBC driver chances are you'll run into this problem:java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]
    Can't start a cloned connection while in manual transaction mode.Simply add SelectMethod=Cursor; to your connection string. There's a MS knowledge base article with more information. The Microsoft SQL Server 2005 JDBC driver has been certified by JBoss Inc.地址:http://www.hibernate.org/120.html
      

  7.   

    意思就是sessionfactory配置错了?
      

  8.   

    sessionfactory只能被创建一次。
    资源用完一定要记得关闭
      

  9.   

    我每段下面都有MySessionFactory.closeSession();的我DEBUG跟踪的时候,发现第一次创建SESSION的时候显示的NULL,等到第一次用完,CLOSE过。但是SESSION不为NULL,而是#XXXX(XXXX为4个数字),这种情况是正常的吗?还是说SESSION没关闭好?
      

  10.   

    hibernate配置文件?我检查了N遍了,我再贴出来看看<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
      <session-factory>
        <property name="connection.url">
    jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=yt;SelectMethod=cursor;
    </property>
        <property name="connection.username">sa</property>
        <property name="connection.password"/>
        <property name="connection.driver_class">
    com.microsoft.jdbc.sqlserver.SQLServerDriver
    </property>
        <property name="dialect">
    org.hibernate.dialect.SQLServerDialect
    </property>
        <!--  在控制台显示SQL语句 -->
        <property name="show_sql">true</property>
        <!-- 配置C3P0连接池属性 -->
        <property name="hibernate.connection.provider_class">
    org.hibernate.connection.C3P0ConnectionProvider
    </property>
        <property name="hibernate.c3p0.max_size">20</property>
        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.timeout">50000</property>
        <property name="hibernate.c3p0.max_statements">100</property>
        <property name="hibernate.c3p0.idle_test_period">3000</property>
        <property name="hibernate.c3p0.acquire_increment">2</property>
        <property name="hibernate.c3p0.validate">false</property>
        <!-- 配置持久化映射文件 -->
        <mapping resource="com/ORM/Memberlevel.hbm.xml"/>
        <mapping resource="com/ORM/Merchandise.hbm.xml"/>
        <mapping resource="com/ORM/Admin.hbm.xml"/>
        <mapping resource="com/ORM/Orders.hbm.xml"/>
        <mapping resource="com/ORM/Cartselectedmer.hbm.xml"/>
        <mapping resource="com/ORM/Cart.hbm.xml"/>
        <mapping resource="com/ORM/Leaveword.hbm.xml"/>
        <mapping resource="com/ORM/Category.hbm.xml"/>
        <mapping resource="com/ORM/Member.hbm.xml"/>
      </session-factory>
    </hibernate-configuration>
      

  11.   

    有新的进展了。。我发现我把多对一的映射删掉,就不会出错了难道是我映射哪里做错了。继续贴代码。大哥们帮帮忙
    <!--映射Merchandise到Category的多对一单向关联-->
        <many-to-one class="com.ORM.Category" column="Category" lazy="false" name="category" not-null="true"/>Category.hbm.xml
    <hibernate-mapping>
      <class name="com.ORM.Category" table="category">
        <id name="id" type="java.lang.Integer">
          <column name="ID"/>
          <generator class="identity"/>
        </id>
        <property name="cateName" type="java.lang.String">
          <column length="40" name="CateName"/>
        </property>
        <property name="cateDesc" type="java.lang.String">
          <column length="65535" name="CateDesc"/>
        </property>
      </class>
    </hibernate-mapping>
      

  12.   

    不是映射的问题,你这个问题是在一个连接中开启了多个Statemant,这个微软有解释的
    你把if (!Hibernate.isInitialized(list))Hibernate.initialize(list); 去掉估计就没错了,这里又开了一个statement应该还是url的问题,就是那个SelectMethod.
      

  13.   

    你的category是一个单独的表?没有相关联的操作?级联操作呀
    org.hibernate.exception.JDBCConnectionException: could not load an entity: [com.ORM.Category#1]
    你的表是不是对应有相关的外键什么的了