自从迁移到Spring 4以来,我遇到了一个奇怪的问题。 Application使用dwr进行Ajax调用。 Ajax帮助程序调用该服务。
错误是
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
AjaxSiteDnsHelper.java
public void removeSiteDnsEntry(Long siteDnsEntryId) throws ItemNotFoundException, ServiceException {
final Site site = getSite();
site.setModifiedBy(getUser());
for (SiteDns siteDns : site.getSiteDnsEntries()) {
if (siteDns.getId().equals(siteDnsEntryId)) {
site.getSiteDnsEntries().remove(siteDns);
break;
}
}
siteServices.saveOrUpdateSite(site);
}
Transactional(readOnly = true)
public class SiteServices extends NavigationServices implements ISiteServices {
//some code
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void saveOrUpdateSite(final Site site) throws ServiceException {
siteDAO.saveOrUpdate(site);
if (site.getExternalFeedUser() == null) {
site.setExternalFeedUser(createDefaultSiteUser(site));
} else {
site.getExternalFeedUser().setUsername("DOD " + URLMappingUtils.generateSiteUgcEditorUsername(site));
}
LOG.info("Setting default user to '" + site.getExternalFeedUser().getUsername() + "'");
userDAO.saveOrUpdate(site.getExternalFeedUser());
}
web.xml已
hibernateOSIV org.springframework.orm.hibernate3.support.OpenSessionInViewFilter sessionFactoryBeanName SessionFactory的
persistence-context.xml有
<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
transactional-context.xml有
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven/>
有人建议我在创建代理时需要重构代码以删除类的层次结构。 我把调试放在OpenSessionInViewFilter.setFlushMode上。但它似乎没有被调用,并且正在使用MANUAL的默认flushmode。