I am wanting to reduce the amount of memory generally a query is using.
I am using Spring Boot Data and Hibernate 5.6.
I have attempted to return an interface projection via a native query using Spring’s annotation driven support but I have read somewhere that all this may really do is fetch the underlying entities and add them to the context and then create proxies over them I.e. still loads and manages the underlying entity?
I’d have assumed that with the projection interface, the entity would not be managed is it’s essentially read only and especially if its a native query?
Even if Spring Data Projections tries to apply some optimizations, what you read is true. It might still read the whole entity and hence be more memory intensive.
I’d recommend you to look into Blaze-Persistence Entity-Views which you can imagine like Spring Data Projections on steroids. It will not only make sure that the underlying query is optimal according to what you want to fetch, but also create no entities whatsoever.