Reputation: 1985
I have relation annotated as following:
@OneToMany( fetch = FetchType.EAGER )
Is possible to do not fetch this relation without changing default fetch type to lazy? I ask obout it because I improve existing application and I don't want to change existing entities and their annotations. In my case I don't need to fetch this relation and fetching it is very computer power consuming so I would like to avoid it. One way to solve it is createing second redundant entity which does not have this relation. Is there a better way?
I use Hibernate as persistence provider.
Upvotes: 0
Views: 927
Reputation: 9102
JPA Implementers such as Hibernate use the global fetch plans like these to create SQL's (to load entities later for e.g., for loading entity by Id instead of creating SQL's every time when required) at EntityManagerFactory bootstrap time and there is not yet any configuration to override these global fetch plans. The two solutions that come to mind are
Upvotes: 2
Reputation: 1457
I am not sure on this, Try specifying the fetch type explicitly in your query, some thing like this:
Criteria crit = session.createCriteria(ParentClass.class);
crit.add(Restrictions.eq("id", id));
crit.setFetchMode("childProperty", FetchMode.LAZY);
Upvotes: 1