Hi, I am upgrading from hibernate 3.1 to hibernate 5.2 and I am running into an issue where I am getting this exception when I call the following method below. It worked fine in hibernate 3.1 but I don’t understand why it says transaction required.

Reading a lot online says to add @Transactional to the method or class and try changing the propegation but it doesn’t seem to work and it will make the Dao object I get from the bean null (the proxy is populated but it doesn’t wrap the object). I contacted spring and they said it is an issue with hibernate so I am looking for some help on this issue. Thanks.

// this is a sample DAO I have (simplified) that is saying transaction required
public class TestDao extends HibernateTemplate {
protected Integer batchSize;

public void updateNames() {
		String deleteHQL = "delete from users";

Application Context:

<bean id="testDao" name="dao" class="com.test.TestDao">
		<property name="batchSize" value="2000" />

When I call TextDao testDao = (TestDao) myContext.getBean("testDao"); with @Transactional, I see this:

1 Like

I suppose you are using Spring, so just follow Spring transaction management guidelines.

Basically, you need a @Transactional service method whenever you want to issue a read-write transaction.

Hi vlad,
I added to the post above, to show what happens when I add @Transactional but…

without @Transactional I see this:

When I create the dao object, the constructor and the setters do not call updateNames. This is the issue I am having and I am not too sure what the issue is.

The constructors and setters have nothing to do with updateNames. The constructors and setters are used for setting up the bean, while the updateNames is what the service beans will call.

Anyway, this is not a Hibernate-related question but a Spring one so you need to ask it either on StackOverflow or on the Spring forums.