问题出在hibernate上,你的hb的配置文件呢?好象是创建的时候产生了同样的id

解决方案 »

  1.   

    我觉得应该不是这个问题,个人觉得问题应该出现在Spring+Hibernate的Transaction.因为如我去掉transactionManager或者把"create*"的事务去掉,就没有异常.
    一下是我的spring+hibernate的配置,我不是单独使用Hibernate的.
    <bean id="dataSource"
           class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName">
    <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="url">
    <value>jdbc:mysql://192.168.8.2:3306/idnms</value>
    </property>
    <property name="username">
    <value>idnms</value>
    </property>
    <property name="password">
    <value>idnms</value>
    </property>
    </bean>
        <bean id="sessionFactory" 
    class="org.springframework.orm.hibernate.LocalSessionFactoryBean"
    >
            <property name="dataSource"><ref bean="dataSource"/></property>
            <property name="mappingResources">
                <list>
                    <value>Xxx.hbm.xml</value>
                    ....
                </list>
            </property>
            <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop>
    <prop key="hibernate.show_sql">false</prop>
    <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
    <prop key="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</prop>
    <!--
                <prop key="hibernate.dialect">net.sf.hibernate.dialect.InformixDialect</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
    -->
            </props>
            </property>
        </bean>
      

  2.   

    the problem is resolved.
    it is maybe a hibernate problem,in my way:using the saveOrUpdateCopy() method to replace the save()
      

  3.   

    the  problem  is  resolved.  
    it  is  maybe  a  hibernate  problem,in  my  way:using  the  saveOrUpdateCopy()  method  to  replace  the  save() .
    但是具体的原因还是不太清楚,为什么加上事务处理以后会出现异常,希望大家继续来讨论.
      

  4.   

    哦,这里:<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">用的hb的jdbc事务,而mysql是不支持事务的,所以就……换成jta可能就没问题了:<bean id="transactionManager" 
            class="org.springframework.transaction.jta.JtaTransactionManager"/>