Warren Nocos
Warren Nocos

Reputation: 1272

Spring Data Streaming query throws no transaction error on JBoss 7 with JTA

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.

enter image description here

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

Answers (1)

Simon Martinelli
Simon Martinelli

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

Related Questions