Hi All,
I hope this isn't a repeat question. I have looked, and google'd, this question for sometime. I am just looking for guidance on the best approach.
The Problem:I have an entity which has 2 Collections which represent a Many-to-Many relationship with 2 other entities. Now I have them both set to be lazily fetched, as I don't require that information all the time.
Question:However in the instances I do want that information, what is the best approach to get them loaded. ?
From Research:I have seen various ways of getting these collections loaded, one being the "EntityManager in View" design pattern, but with my beliefs leaning toward the pure computer science side, it just doesn't feel right. Another is to have a facade that calls on those collections, forcing Hibernate to populate them.
E.g.
Code:
@Transactional
public MyEntity getMyEntity(Long id) {
// Call to underlying service method
MyEntity rtn = service.getMyEntity(id);
// Force Hibernate to load the collections
rtn.getCollection1().size();
rtn.getCollection2().size();
return rtn;
}
Again, I don't feel comfortable with this. Maybe I am being overly pure and missing something glaringly obvious, this may not even be a problem at all and I have over-complicated things.
Would be great if someone else offered their insight into this problem.
Kind Regards to All
Cookie