Transactions in Spring / Hibernate / appfuse
As a follow up to the question here: Spring 2.0 Annotations and ant
We were able to get the annotations working (@Transactional), and also tried manually coding a Transaction.
In both cases, we are getting some problems. This is an appfuse 1.9.4 project, where we manually upgraded to a newer Hibernate project. This is using Spring 2.0.
What I'd like to do is to wrap an entire web service in a database "Transaction", so that the entire "call" is atomic. I understand that the "easiest" way to do this is with @Transactional?
To do so, we added to our class:
import org.springframework.transaction.annotation.Transactional;
And then, next to the method (which is public), we did:
@Transactional (readOnly = false, rollbackFor=Exception.class)
public List processEmployees(List employees){
....
}
In to applicationContext-hibernate.xml, I added:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
Now, when I start Tomcat, I get this lovely error:
[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 except开发者_如何学JAVAion 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.
We are using Spring 2.0, but do not have any AOP "configured".
Any ideas?
Alternatively, I'm happy to do this with Transaction.commit(), but going that route throws a message about the transaction never being started.
Thanks!
You didn't define the "tx" namespace in your applicationContext-hibernate.xml
. Thus the XML parser can't identify the element.
精彩评论