Tim Holloway wrote:
One thing I should mention is that if you're attempting to use an Entity as a backing bean, don't. That strategy doesn't work very well, since JSF isn't flexible enough to vary which instance of the entity you're referencing.
Tim Holloway wrote:You probably are working with detached objects, then.
A lot of people cheat and plug in a component that keeps the object attached throughout the whole request, but I don't like that idea. To me, it's sloppy. Among other things, it means that something could modify the data somewhere else and you wouldn't know it. I prefer to compartmentalize: UI interface and general business logic (detached). Transactional business logic (attached), and low-level persistence logic (finders, save, update - also attached).
Tim Holloway wrote:One problem with using detached objects is what you ran into. You can eager-fetch the dependencies, but if you're not careful, you can end up sucking almost the entire database into RAM. Multiple times. So my transactional business logic generally incorporates the idea of "working sets", which are related objects treated as a unit, with the dependencies force-fetched, leaving the actual model set for Lazy fetching.