0

I am not sure what class to use for model in this 3 tier architecture with struts 2 as my MVC.

Use case: Retrieve Destination (city) with a given name.

Architecture: Struts 2 MVC (Action) -> Service -> DestinationDAO

Struts 2: View <---> Action (and this action invokes service layer)

DestinationDAO uses hibernate and has a function getDestination(String name) to retrieve a destination from the database.

My question is: The action class needs to have a property that I can use for displaying destination info with the jsp. Should I use my Destination POJO (that I use with hibernate) or should it be a different object ?

I'd appreciate any suggestions/links to read on this subject.

brainydexter
  • 19,826
  • 28
  • 77
  • 115

1 Answers1

1

Though you can use Your Destination POJO as the DO for your view, but i will not recommend this approach and some time it can create an undesirable behavior which is hard to debug.One of such use-case is auto triggering of Hibernate queries when some changes being done in the Model (POJO).

Create set of DTO's with the required properties which are required to render the view and use these DTO as your Model object for MVC (Struts2). While calling your service layer you can copy the values from your DTO to POJO, which will make the layers more decoupled and easy to change.

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204