日期:2014-05-18  浏览次数:20660 次

关于Spring声明式事物配置问题
本帖最后由 tracy19880727 于 2013-07-10 10:43:41 编辑
最近正在学习spring的声明式事物管理,遇到配置声明式事物后无法写入记录到数据库(数据库用的sql server 2008),话不多说,上代码:
下面是配置的声明式事物管理代码:

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"></property>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_SUPPORTS</prop>
<prop key="query">PROPAGATION_SUPPORTS,readOnly</prop>
</props>
</property>
</bean>

<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*ServiceImp</value>
</property>
<property name="interceptorNames">
 <list>
  <value>transactionInterceptor</value>
 </list>
</property>
</bean>

service层的接口和实现类代码如下:

public interface FileListService {
public void add(ZipFileDto dto);
}

public class FileListServiceImp implements FileListService {
public FileListDao fileListDao;
public void setFileListDao(FileListDao fileListDao) {
this.fileListDao = fileListDao;
}
public void add(ZipFileDto dto) {
fileListDao.add(dto);
}
}

在线等!解决问题的果断给分!!!!!(PS:hibernate有打印insert语句,但是数据库没有记录!)

------解决方案--------------------
没有交给session管理。。。。
------解决方案--------------------