This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Integrating Struts2 with Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Integrating Struts2 with Hibernate" Watch "Integrating Struts2 with Hibernate" New topic
Author

Integrating Struts2 with Hibernate

RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
I want to develop a web application using Struts2 as my UI and Hibernate as my Model.

I made a Hibernate Util class for opening and closing session.

Please tell me will it be a right approach if i use Interceptors for getting reference to session in Util class. If not then what is the best place ?

Anybody please help.


If you want something you never had do something which you had never done
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Well I have the Struts 2 in Action book and in that they have used Spring as a middle man to make Struts work with Hibernate. And the flow is really simple. If you like this idea, then you can look at these pages

http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html

http://www.codeweblog.com/struts2-spring-hibernate-s-easy-to-integrate/

http://www.vitarara.org/cms/struts_2_cookbook/integration_testing


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
kurt hanni
Ranch Hand

Joined: Aug 11, 2007
Posts: 140


Yes you could do it with interceptors.

or you can add spring in your integration, and use spring-AOP for opening and closing hibernate sessions/transactions. Spring has great support for hibernate and would relieve you of writing lots of boilerplate code. You'll find you're coding and structure much simpler.

SCJA, SCJP, SCJD, SCMAD, SCWCD, SCBCD, SCDJWS, SCEA, SOA, Spring Certified, OCP MySQL 5 Developer, PMP
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Thanks Hanni and Ankit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Integrating Struts2 with Hibernate
 
Similar Threads
Struts2 hibernate one-to-one Mapping
Struts2 + Hibernate
Struts2
setting scope of variable in Struts2
struts2