0

I am getting HibernateSystemException although I did everything that is mentioned on different forums.

Here is a part of applicationContext.xml

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
</bean>

I also placed @Transactional annotaion above my class.

@Transactional
public class MyClassImpl

4 Answers 4

2

A) this is the wrong transaction manager:

<bean id="transactionManager" 
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
</bean>

you need org.springframework.orm.hibernate3.HibernateTransactionManager, as you can see in 13.3.3 Hibernate > Declarative transaction demarcation.

DataSourceTransactionManager is for plain JDBC, not for Hibernate (see 12.3.8 JDBC > DataSourceTransactionManager).

B) you need this line also:

<tx:annotation-driven transaction-manager="transactionManager" />
Sign up to request clarification or add additional context in comments.

3 Comments

Our another application is running with the transactionManager I mentioned in my question.
@imran ok, then the other app uses JDBC, not Hibernate. If the two run in parallel, you'll need two different transaction managers, see this bit for advice: static.springsource.org/spring/docs/3.0.x/…
I was using @Transactionalbut it was not working. Actually I my class was not in the base package as defined in the applicationcontext.xml file.
1

Have you checked that this markup is present in you application context file ?

<context:annotation-config />

It is necessary to consider your annotations.

4 Comments

This markup is not present in my application context file. Our another application is running successfully without this markup.
@Alex I can see no hint in the Spring docs that this is needed
@Sean Patrick Floyd You're right. Actually, this markup is only needed to activate Spring various annotations such as Autowired, PostConstruct, PreDestroy and Resource. My apologies...
@Alex to be clear: this annotation makes perfect sense and it's a great thing to have. It's just not required for this functionality.
0

Did you include the tx namespace in your configuration?enter image description here

2 Comments

In my applicationContext.xml. tx is used like this <tx:annotation-driven/>
@imran tariq, if using Springsource Tool Suite, at the bottom of the editor for your xml file you should see a tab called namespaces, click on the the namespaces tab and make sure tx is checked.
0

Before doing any request, you could try this piece of code :

Session session = SessionFactoryUtils.getSession(dataSource, null, null);
TransactionSynchronizationManager.bindResource(dataSource, new SessionHolder(session));

Please keep me informed.

1 Comment

The whole point of using Spring's declarative transaction management is so we don't have to write infrastructure code like that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.