Image
image
image
image


Struts & Hibernate Integration :

Struts integration with Hibernate using Struts1.2/1.3 framework needs a bit of extra work because sturs1.2/1.3 form beans are not POJO classes. As we know hibernate works with POJO's.Here we create separate POJO class for holding persisting data. This POJO object is populated with the form data which is available in the struts form bean.

One more important point here is the creation of a Hibernate Session .We have different approaches for creating Hibernate Session like using Plug-In,separate Utility class or embedding directly in to the code.Each way has its pros and cons.

If we use the Plug-In for creating Hibernate Session it is better to place the Hibernate Session Object in the Application Scope so that any struts action that wants hibernate session can easily get it.From the coding point of view the Plug in class has to implement the plug-in interface.The plig-in class has to be mentioned in the web.xml using plug-in tags.

For the sake of simplicity i used the Utility class for creating hibernate session.In the following code sample.

Code of: hinernate.cnf

 

Hibernate Mapping File : SignUp.hbm

Persistence POJO class: SignUp.java


Source Code for Untility Class: HibernateUtil.java



Persistence logic is separated through DAO pattern .Following is the code for login & SignUp DAO's

Code for LoginDAO.java

 

Code for SignUpDAO

Login Business Logic is seperated through BO pattern.Following is the code for Logic and SignUp BO's .Interfaces are used to provode the loose coupling

Code for iLoginBO interface

Code for LoginBOimpl this calss implements the iLoginBO interface

Code for iSignUpBO interface

Code for SignBOimpl

 


Code for SignUpAction class

Code For LoginAction Class



For technical support please contact me at

murali@javamission.com



image


image
image