Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2537415
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: Java

2011-09-16 17:07:53

Struts 2 + Hibernate integration example

In Struts2, there are no official plugins to integrate the Hibernate framework. But, you can workaround with the following steps :

  1. Register a custom ServletContextListener.
  2. In the ServletContextListener class, initialize the Hibernate session and store it into the servlet context.
  3. In action class, get the Hibernate session from the servlet context, and perform the Hibernate task as normal.

See the relationship :

Struts 2 <-- (Servlet Context) ---> Hibernate <-----> Database

In this tutorial, it shows a simple customer module (add and list function), developed in Struts 2, and perform the database operation with Hibernate. The integration part is using the above stated mechanism (store and retrieve the Hibernate session in the servlet context).


Struts + Spring + Hibernate integration example



In this tutorial, it shows the integration between “Struts2 + Spring + Hibernate“. Make sure you check the following tutorials before continue.

See the summary of integration steps :

  1. Get all the dependency libraries (a lot).
  2. Register Spring’s ContextLoaderListener to integrate Struts 2 and Spring.
  3. Use Spring’s LocalSessionFactoryBean to integrate Spring and Hibernate.
  4. Done, all connected.

See the relationship :

Struts 2 <-- (ContextLoaderListener) --> Spring <-- (LocalSessionFactoryBean) --> Hibernate



阅读(1643) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~