简体   繁体   中英

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 AI 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,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM