Till
Till

Reputation: 994

Switch fetch mode with spring-data and jpa

I have a pretty large count of entity classes with lots of relationships between them. I'm using spring-data-jpa with hibernate. Almost all the fetch modes are set to lazy. I was wondering if there is a chance to get eager fetching for the first level and lazy for the next one.

Example:

class EntityA {
     EntityB propertyB;
}
class EntityB {
     EntityC propertyC;
}

When I load entity B directly I would like entity C to be fetched eagerly. If I load entity A I want only entity B fetched eagerly and entity C lazy.

I know this can be accomplished with specific queries but I would like to avoid writing queries for every single entity.

I hope I'm making sense here. Any hints are highly appreciated.

Thanks,

Upvotes: 1

Views: 2217

Answers (1)

Thomas Darimont
Thomas Darimont

Reputation: 1376

This is (currently) not supported by Spring Data JPA and we already have a feature request for this. I linked this discussion to the issue: https://jira.spring.io/browse/DATAJPA-466

Cheers, Thomas

Upvotes: 1

Related Questions