-
Notifications
You must be signed in to change notification settings - Fork 366
Demonstrate solution for lazy-loading #33
Comments
Reported by danpeter |
Was assigned to reza_rahman |
danpeter said: For more complex domain models the extended entity manager looks promising. I put this very simple sample together: |
reza_rahman said: First a few comments on the code for your consideration:
Did you get a chance to check with the DDD community as to their thoughts on lazy loading? Last I checked, the consensus appeared to be that lazy loading was largely antithetical to DDD practices as indicated on this thread as an anecdote: http://stackoverflow.com/questions/15851122/domain-driven-design-entity-lazy-loading. That being said, I would not go so far as to categorizing lazy loading into an anti-pattern. Clearly there are cases where it is a valid technique. I just want to know what the current thinking is (I am sure this issue had to have been discussed). Going the more classical DDD route, one option that might be of interest is JPA 2.1 entity graphs: http://www.datanucleus.org/products/datanucleus/jpa/entity_graphs.html. Another interesting observation is that lazy loading actually is dealt with somewhat gracefully using DTOs at the application layer. It's only in the simplified layering case that I was trying to demonstrate that appears more complexity need be introduced in the repository layer... Thoughts? |
danpeter said: The nice thing with the extended persistance manager is that I can fetch the aggregate root object and traverse/modify the object graph in the the UI over several http request. Then when I am finished I call the save method on the reposity and all changes will be persisted/merged. Using the Word "flush" in the comment may have been a mistake. Your stackoverflow link has a valid Point, maybe I am mixing DDD and data access too much. I will have a look at entity graphs. |
reza_rahman said: I am also aware of Adam's views on DDD and unfortunately differ from them. In my long years of enterprise development, I can't begin to cite examples when layering and API abstraction has proven to be invaluable in keeping systems flexible, maintainable and technology agnostic in the long run. That being said, we should document those views in this project as valid alternatives to choose, especially for relatively small, simple, young greenfield systems (sans the somewhat understandable misinterpretation/misunderstanding of the JPA automatic transaction enrollment/flush capability). |
This issue was imported from java.net JIRA CARGOTRACKER-33 |
Closing this as this issue is migrated to eclipse-ee4j/cargotracker#33 |
In the application some JPA relations are one-to-many and by default lazy loaded. When fetching the aggregate-root through the repository the returned root object will be detatched. Eclipselink handles this for read operations but Hibernate would throw a LazyInitializationException.
A traditional solution would be to add methods to a DAO such as loadCargoWithLoadedLegs();
With a lot of lazy collections and many combinations this would quickly be a bloated interface.
As a developer I would like to fetch the root, access and make changes to any object in graph, then store the root and have all changes persisted.
The text was updated successfully, but these errors were encountered: