Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 933 Vote(s) - 3.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spring - No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call

#11
I had the same error because I switched from XML- to java-configuration.

The point was, I didn't migrate `<tx:annotation-driven/>` tag, as Stone Feng suggested.

So I just added `@EnableTransactionManagement` as suggested here

[To see links please register here]

, and it works now
Reply

#12
I had the same problem and I added `tx:annotation-driven` in `applicationContext.xml` and it worked.
Reply

#13
This helped us, maybe it can help others in the future. `@Transaction` was not working for us, but this did:

`@ConditionalOnMissingClass("org.springframework.orm.jpa.JpaTransactionManager")`
Reply

#14
Adding the `org.springframework.transaction.annotation.Transactional` annotation at the class level for the test class fixed the issue for me.
Reply

#15
Just a note for *other* users searching for answers for thie error. Another common issue is:

> You generally cannot call an `@transactional` method from within the same class.

*(There are ways and means using AspectJ but refactoring will be way easier)*

So you'll need a calling class and class that holds the `@transactional` methods.







Reply

#16
If you have

@Transactional // Spring Transactional
class MyDao extends Dao {
}

and super-class

class Dao {
public void save(Entity entity) { getEntityManager().merge(entity); }
}

and you call

@Autowired MyDao myDao;
myDao.save(entity);

you won't get a Spring TransactionInterceptor (that gives you a transaction).

This is what you need to do:

@Transactional
class MyDao extends Dao {
public void save(Entity entity) { super.save(entity); }
}

Unbelievable but true.
Reply

#17
I got the same error when I executed the Spring JPA ```deleteAll()``` method from Junit test cases. I simply used the ```deleteInBatch()``` & ```deleteAllInBatch()``` and its perfectly works. We do not need to mark ```@Transactional``` at the test cases level.
Reply

#18
For anyone with the same issue as I had, I was calling a public method `method1` from within another class.
`method1` then called another public method `method2` within the same class.
`method2` was annotated with `@Transactional`, but `method1` was not.
All that `method1` did was transform some arguments and directly call `method2`, so no DB operations here.

The issue got solved for me once I moved the `@Transactional` annotation to `method1`.

Not sure the reason for this, but this did it for me.
Reply

#19
Without @Transactional annotation you can achieve the same goal with finding the entity from the DB and then removing that entity you got from the DB.

CrudRepositor -> void delete(T var1);
Reply

#20
Calling the repository method was being called within a class with @Component, taking that method out of that class and placing it inside another with @Service worked.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through