When trying to stream results from Microsoft SQL Server 2014 I always get an SQLServerException: The result set is closed. Also tried with selectMethod=cursor in the JDBC URL to no avail. Is there something MSSQL specific to consider? Using Spring Boot 1.4.0.RELEASE, Spring Data JPA 1.10.2.RELEASE.
Sample repository interface:
package sample;
import sample.Contact;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.stream.Stream;
@Repository
public interface MyRepository extends JpaRepository<Contact, String> {
Stream<Contact> findByContactid(String contactid);
}
I've found that making the service method that is calling the repository be inside of a transaction gets rid of this error for me.
@Transactional(readOnly=true)
public List<Results> myServiceMethod() {
return repo.findByContactid("12345").map(c->c.getName()).collect(toList());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With