I have been trying to fetch 2.5M rows from oracledb. I use pagination of 100k. My table is a view table so there are no references to other tables. Spring boot uses by default open-in-view = true. When I use the default after the first 800k records the app crashes with "java.lang.OutOfMemoryError: Java heap space" I have tried to increase the memory that my app uses but still get the same error. If I set open-in-view = false then all the data are fetched but then every entity in my app that uses FetchType.Lazy does not work (LazyInitializationException).
Is there any way to enable open-in-view only in specific controllers? Any suggestions?
Spring Boot: v2.5.3 Oracle: 12c Datasource-type: oracle.ucp.jdbc.PoolDataSource
@RequestMapping
@RestController
@AllArgsConstructor(onConstructor_ ={@Autowired})
public class ExportRestApi(){
private ExportServiceImpl exportServiceImpl
@PostMapping
public exportDto exportData(){
return this.exportServiceImpl.export()
}
}
My Service
@Service
@Transactional
@AllArgsConstructor(onConstructor_ ={@Autowired})
public class ExportServiceImpl(){
private ExportRepository exportRepository
@Transactional
public exportDto export(){//iterate here per page
return this.exportRepository.findAll(page,size)).getContent()
}}
@Repository
public interface ExportRepository extends JpaRepository<ExportEntity,String){
@Query(value = "select * from {table} offset :page rows fetch next :size rows only)
List<ExportEntity> findAll(page,size)
}