I had the following JSF backing bean in my Webapp
@ManagedBean
class MyBackingBean implements Serializable {
private MyHibernateRepository repository;
...
@Transactional
public void save() {
....
repository.save(myObject);
}
}
When it gets to the repository.save
method call - I get the following error
no transaction is in progress
I've got two questions
- Is this because of a bug like this?
- I believe there are two workarounds - are there any others?
2.1 First workaround - using
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
repository.save(myObject);
}
});
2.2 Second workaround
Create a helper class and annotate that instead.
2.3 (A possible third workaround would be to annotate @Transactional on a method of an inner class This is quite similar to 2.2).