aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Working with complex detached object graphs in EJB3 or hibernate in 3-tier architecture Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Working with complex detached object graphs in EJB3 or hibernate in 3-tier architecture" Watch "Working with complex detached object graphs in EJB3 or hibernate in 3-tier architecture" New topic
Author

Working with complex detached object graphs in EJB3 or hibernate in 3-tier architecture

Frankie Fuentes
Ranch Hand

Joined: Mar 28, 2010
Posts: 41
Hi,

My setup is something like this:

Servlet(JSF) <-> Business Facade <-> Remote EJBs

My domain model is quite complex, something like this:



What would be the best practice to send a complex graph of objects to the business facade to do CRUD operations on this complex graph? Say, the servlet client deleted and updated some objects somewhere deep in the object graph, basically how would the service layer know which are updated, deleted, and which are new? I'm working with detached object, and couldn't have an open session (persistent context) because this is a 3-tier architecture.

Much appreciated. Thanks.
Billy Vandory
Ranch Hand

Joined: Mar 23, 2010
Posts: 57
Frankie Fuentes wrote:Hi,

My setup is something like this:

Servlet(JSF) <-> Business Facade <-> Remote EJBs

My domain model is quite complex, something like this:



What would be the best practice to send a complex graph of objects to the business facade to do CRUD operations on this complex graph? Say, the servlet client deleted and updated some objects somewhere deep in the object graph, basically how would the service layer know which are updated, deleted, and which are new? I'm working with detached object, and couldn't have an open session (persistent context) because this is a 3-tier architecture.

Much appreciated. Thanks.




This is quite interesting because I just had the exact same problem using the same design. What I did was to set a dirty flag in the transfer object whenever one of the mutators change the objects state. I used spring's AOP to create a point cut expression around the setters in the transfer object and check if the hashCode value has changed; if there is a change, i set the dirty flag to true.

When the object graph is passed to the service layer for update, the graph is unwrapped and only objects with the dirty bit set are updated.

Frankie Fuentes
Ranch Hand

Joined: Mar 28, 2010
Posts: 41
Thanks Billy, I guess creating another transient property for the purpose of flagging an entity dirty or new or deleted is really a manageable approach. I couldn't think of anything better than that unless I perceive keeping a separate collection of entities for every state a good idea. The project we've been doing has been manageable so far using this approach. Although it imposes a programming model for the entire team to remain consistent, it's worth it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Working with complex detached object graphs in EJB3 or hibernate in 3-tier architecture