1

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)
    }
    
pithas
  • 11
  • 2
  • Paginating 100k is a bad idea. Also instead of lazily loading dynamically, you can initialize that data on the loading of context/service/controller. Share your code snippets of the controller/service/view so that you can get some suggestions. – Ajay Kumar Nov 02 '21 at 12:52
  • Okay. You can try few options here and share the outcome -https://stackoverflow.com/questions/15359306/how-to-fetch-fetchtype-lazy-associations-with-jpa-and-hibernate-in-a-spring-cont – Ajay Kumar Nov 03 '21 at 16:56

0 Answers0