簡體   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