繁体   English   中英

Spring / Hibernate / appfuse中的事务

[英]Transactions in Spring / Hibernate / appfuse

作为这里的问题的后续跟进: Spring 2.0 Annotations和ant

我们能够使注释工作(@Transactional),并尝试手动编写事务编码。

在这两种情况下,我们都遇到了一些问题。 这是一个appfuse 1.9.4项目,我们手动升级到一个较新的Hibernate项目。 这是使用Spring 2.0。

我想要做的是将整个Web服务包装在数据库“Transaction”中,以便整个“调用”是原子的。 我知道“最简单”的方法是使用@Transactional吗?

为此,我们在课堂上添加了:

import org.springframework.transaction.annotation.Transactional;

然后,在方法(公共)旁边,我们做了:

@Transactional (readOnly = false, rollbackFor=Exception.class)
public List processEmployees(List employees){
  ....
}

在applicationContext-hibernate.xml中,我添加了:

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<tx:annotation-driven transaction-manager="transactionManager"/>

现在,当我启动Tomcat时,我得到了这个可爱的错误:

[Scheduler] 2011-08-22 12:57:03,032 ERROR [main] ContextLoader.initWebApplicationContext(205) | Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Line 153 in XML document from ServletContext resource [/WEB-INF/applicationContext-hibernate.xml] is invalid; nested exception is org.xml.sax.SAXParseException: The prefix "tx" for element "tx:annotation-driven" is not bound.
Caused by: 
org.xml.sax.SAXParseException: The prefix "tx" for element "tx:annotation-driven" is not bound.

我们使用的是Spring 2.0,但没有“配置”任何AOP。

有任何想法吗?

或者,我很高兴使用Transaction.commit()执行此操作,但是该路由会抛出有关事务永远不会启动的消息。

谢谢!

您没有在applicationContext-hibernate.xml定义“tx”命名空间 因此,XML解析器无法识别该元素。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM