楼上说的你注意一下,如果,使用的是数据源,那么检查下,是否设置的 readonly属性

解决方案 »

  1.   

    applicationContext.xml 
    文件如下:
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
      <!-- ========================= Start of PERSISTENCE DEFINITIONS ========================= -->
      <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
          <value>/WEB-INF/classes/init.properties</value>
        </property>
      </bean>
      <!-- Choose the dialect that matches your "dataSource" definition -->
      <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName">
          <value>${datasource.driverClassName}</value>
        </property>
        <property name="url">
          <value>${datasource.url}</value>
        </property>
        <property name="username">
          <value>${datasource.username}</value>
        </property>
        <property name="password">
          <value>${datasource.password}</value>
        </property>
        <property name="maxActive">
          <value>${datasource.maxActive}</value>
        </property>
        <property name="maxIdle">
          <value>${datasource.maxIdle}</value>
        </property>
        <property name="maxWait">
          <value>${datasource.maxWait}</value>
        </property>
        <property name="defaultAutoCommit">
          <value>${datasource.defaultAutoCommit}</value>
        </property>
      </bean>
     
      <bean id="mySessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
      
      
        <property name="dataSource"><ref local="dataSource"/></property>
        <property name="mappingResources">
          <list>   

    <value>com/doallin/bean/Test.hbm.xml</value>
    <value>com/doallin/bean/TbUserinfo.hbm.xml</value>

    </list>
        </property>
        <property name="hibernateProperties">
          <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop>
            <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
          </props>
        </property>
      </bean>
      
      <bean id="myTransactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
        <property name="sessionFactory">
          <ref local="mySessionFactory"/>
        </property>
      </bean> 
      

    <bean id="testDAO" class="com.doallin.service.dao.hibernate.TestHibernateDAO">
        <property name="sessionFactory">
          <ref local="mySessionFactory"/>
        </property>
      </bean>  
      <bean id="testService" class="com.doallin.service.spring.TestServiceSpringImpl">  
    <property name="testDAO"><ref local="testDAO"/></property>
    </bean>  

    <bean id="userDAO" class="com.doallin.service.dao.hibernate.UserHibernateDAO">
        <property name="sessionFactory">
          <ref local="mySessionFactory"/>
        </property>
      </bean>  
      <bean id="userService" class="com.doallin.service.spring.UserServiceSpringImpl">  
    <property name="userDAO"><ref local="userDAO"/></property>
    </bean>  </beans>
      

  2.   

    init.properties
    文件如下:
    datasource.driverClassName=org.gjt.mm.mysql.Driver
    datasource.url=jdbc:mysql://localhost:3306/doallin
    datasource.username=root
    datasource.password=111111
    datasource.maxActive=10
    datasource.maxIdle=2
    datasource.maxWait=120000
    datasource.defaultAutoCommit=false
    datasource.whenExhaustedAction=1
    datasource.validationQuery=select 1 from dual
    datasource.testOnBorrow=true
    datasource.testOnReturn=falsehibernate.dialect=net.sf.hibernate.dialect.MySQLDialect
    hibernate.jdbc.batch_size=25
    hibernate.jdbc.fetch_size=50
    hibernate.show_sql=true
    hibernate.hbm2ddl.auto=create-drop
      

  3.   

    TbUserinfo.hbm.xml
    文件如下:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
                                "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
                                "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" ><!-- DO NOT EDIT: This is a generated file that is synchronized -->
    <!-- by MyEclipse Hibernate tool integration.                   -->
    <!-- Created Thu Mar 30 12:00:15 CST 2006                         -->
    <hibernate-mapping package="com.doallin.bean">    <class name="TbUserinfo" table="tb_userinfo">
            <id name="id" column="id" type="integer">
                <generator class="native"/>
            </id>
     
            <property name="rid" column="rid" type="integer"  not-null="true" />
            <property name="username" column="userName" type="string" />
            <property name="type" column="type" type="short"  not-null="true" />
            <property name="password" column="password" type="string" />
            <property name="recordtime" column="recordTime" type="string" />
            <property name="validtime" column="validTime" type="string" />
            <property name="state" column="state" type="short" />
            <property name="comment" column="Comment" type="string" />
            <property name="modifytime" column="ModifyTime" type="string" />
        </class>
        
    </hibernate-mapping>
      

  4.   

    可以了
    是这里错了
    datasource.defaultAutoCommit=false --》true;