Can anyone suggest me the best approach to decouple the hibernate layer from my struts web tier. I was thinking of a session bean masking the hibernate layer or a java class which has methods exposed for the users to call and will talk to the hibernate on behalf. Thanks Kalpana
- Posted by: Ramana Neelam
- Posted on: October 22 2007 15:03 EDT
- struts, hibernate decoupling by Prasanta Dash on October 30 2007 07:36 EDT
- Re: struts, hibernate decoupling by Jeroen Wenting on October 31 2007 04:48 EDT
- Re: struts, hibernate decoupling by J Dev on November 01 2007 10:32 EDT
- Re: struts, hibernate decoupling by guddu sh on November 02 2007 04:17 EDT
- DTO vs entities by etienne laverdiere on November 02 2007 06:15 EDT
- Re: struts, hibernate decoupling by Ramana Neelam on November 12 2007 13:16 EST
The best approach would be to have a business delegate pattern, which will invoke the hibernate calls. You can make use the helper pattern, where you do the exact implementations of the business logics in the helper classes. The methods of the helper class will be invoked from the business delegate. This way you can decouple the struts and hibernate.
Put Spring in between. Spring controllers can controls Hibernate and Struts, passing requests and replies back and forth between the two with neither being aware of the existence of the other (or indeed of Spring being there at all).
Create services, services will use dao for crud operations. And use this services in your actions. and you will not have even a single line of code in your action You can use spring to make things even more easier, specially for hibernate. jYog
This is a similar kind of question, I had in mind sometime back, then I found a good resource as follows: http://question2answer.googlepages.com/data-access-object-DAO.html This helped me in getting an idea about how to decouple model layer from persistence layer. Hope this helps. Thanks.
An important question you need to see is related to the kind of object you will show in the Struts layer. In a simple application, and for some simple processes, you might prefer transferring the domain model pojos (Hibernate entities) directly in the Struts layer. Therefore you will use the "open session in view" pattern already implemented by both Hibernate and Spring. For some other cases, when the web layer is modifying the transfered object, you might need to use DTOs to separate the view, business and model layers. But this is not an obvious choice. Using DTOs is sometime a waste of time and code, but it can prevent the application of falling in some Hibernate "not wanted and uncontrolled" features like transaction, save & update handling to name few. regards,
Thank you all, for your replies.