0

Is it possible to get the data from spring-data JPA in the form of CSV data instaed of ArrayList of pojos like

Below is the interface extending JpaRepository.

public interface FactAggRepository extends JpaRepository<FactAggRepository,Integer> {

@Query("select p from FactAggRepository as p where p.pId=:pId and p.periodStart=:periodStart")
public List<FactAggRepository> getAggregates(@Param("pId") Long pId,@Param("periodStart")LocalDateTime periodStart);

@Query("select p from UsageAgg as p where p.pId=:pId")
public List<UsageAgg> UsageAggregates(@Param("pId") Long pId);

}

Autowiring the repository to use the same methods as follows.

fetchedRecord = AggRepo.getAggregates(pId, periodStart);

Now the above the code returnd the List. Is it possible to get the CSV file with the data in the List without any conversion.please let me know. Thanks in advance.

1 Answer 1

1

Spring Data is here to handle communication with data sources layers. Unfortunately, CSV is not a data store handled natively.

You have to use a third-party dependency such as OpenCSV to transform those POJOs to CSV.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.