• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 57
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic