最近有项目需要用到多数据库,利用hibernate+spring+jotm使用jta事务,我本来不会,在网上找例子程序,然后自己写了个小例子,但是出现了不会提交的问题,启动tomcat不报错,执行save方法也没有问题,在控制台中也打印了insert语句,但是,数据库中查询的时候发现,没有成功插入,试了几次还是一样,然后我在数据库中直接用sql语句插入,结果发现,其实插入操作是成功的,但是没有commit,因为我写的这个例子id是自动增长,从1开始,我直接在数据库中插入后,id已经变成5了,因为我前面在程序中插入了4次,但是没有一次提交成功的,既然在tomcat启动不报错,而且控制台又有打印出insert语句,那么应该是没有commit的了,大家帮我看看配置文件,有没有什么问题,如果大家有成功的类似的例子,也可以发一个给我,谢谢,邮箱:[email protected]<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="sessionFactory2" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate2.cfg.xml</value>
</property>
</bean>
<bean id="personDao" class="com.test.dao.impl.PersonDaoImpl" scope="singleton">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="personDao2" class="com.test.dao.impl.PersonDao2Impl" scope="singleton">
<property name="sessionFactory">
<ref bean="sessionFactory2"/>
</property>
</bean><bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" />

<bean id="myTxManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="userTransaction" ref="jotm" />
</bean><bean id="myService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
       <property name="transactionManager" ref="myTxManager"/>
    <property name="target">
     <ref local="personService"/>
    </property>
<property name="transactionAttributes">
   <props>
        <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="create*">PROPAGATION_REQUIRED</prop>
   </props>
 </property>
</bean><bean id="personService" class="com.test.service.impl.PersonServiceImpl">
<property name="personDao" ref="personDao"/>
<property name="personDao2" ref="personDao2"/>
</bean>以上就是applicationcontext.xml的配置,就实现一个两个数据库的增删改查而已。hibernate.cfg.xml也是一个普通的映射,数据源都配在这里。没其他东西,这里是包含进来。