I can't guess what is wrong with my configuration. I need to use hibernate method within ApplicationListener, but constantly getting this error:
Could not obtain transaction-synchronized Session for current thread
despite the usage of @Transactional under method. This is ApplicationListener implementation:
@Component
public class FillIdOnStartup implements ApplicationListener<ContextRefreshedEvent>
{
@Inject
private MyRepository repository;
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent)
{
Iterable<Provider> products = repository.findAll();
}
}
This is how findAll() method looks like:
@Override
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public Iterable<T> findAll()
{
return session().createQuery("from " + entityClass.getName()).getResultList();
}
What is wrong? Thank you