A select * on a large (14 million row) table issued by our hand-crafted Java object relational manager often hangs. Basically, the code issues this query:
import org.mountsinai.foo.Entity;
import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
// aDataSource is defined ...
NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(aDataSource);
RowMapper<Entity> entityRowMapper = (ResultSet rs, int rowNum) -> {
Entity entity = new Entity();
entity.setDatabaseId(rs.getInt("id"));
entity.setEntityId(rs.getString("entity_id"));
entity.setFound(rs.getBoolean("found"));
// Set 10 more fields ...
return entity;
};
jdbcTemplate.query("select * from table;", entityRowMapper);
Thus we're using NamedParameterJdbcTemplate's query(String sql, RowMapper rowMapper) method. We use the com.microsoft.sqlserver:mssql-jdbc JDBC library.
The query goes to an SLQ Server database. Sometimes everything works, especially when the table is small.
But when the table is large (14 million row), jdbcTemplate.query often hangs. In this circumstance, an SQL Server Profiler trace of the database shows that the query finishes, as we see
SP:StmtCompleted
RPC:Completed
EventClasses for the it in the trace. No exception is thrown at the client.
I'm thinking of trying to fix this problem by replacing the code which fails intermittently with a findAll call that uses Pageable in the PagingAndSortingRepository interface. Would you expect that to solve the problem?
Arthur