Reputation: 1272
I'm trying to integrate Spring Data with my Java EE app. I am deploying this to JBoss 7.0. I have an EJB that calls a data access object operation, but keeps on throwing the following exception even though my EJB has a running container-managed transaction.
org.springframework.dao.InvalidDataAccessApiUsageException: You're trying to execute a streaming query method without a surrounding transaction that keeps the connection open so that the Stream can actually be consumed. Make sure the code consuming the stream uses @Transactional or any other way of declaring a (read-only) transaction.
Did I miss something? Or is it not possible to integrate container-managed transaction with Spring Data on a Java EE app?
Upvotes: 0
Views: 641
Reputation: 36103
How are you trying to integrate Spring Data with the EJB?
You must create the repository with a factory and pass the EntityManager:
@Stateless
public class ExampleBean {
@PersistenceContext
EntityManager entityManager;
public Example findExample(String name){
JpaRepositoryFactory jpaRepositoryFactory=new JpaRepositoryFactory(entityManager);
ExampleRepository repository = jpaRepositoryFactory.getRepository(ExampleRepository.class);
return repository.findOne(name);
}
}
Upvotes: 1