Magazine
 
Integrating JSF, Spring and Hibernate
 

<managed-bean>
<managed-beanname>
CheckValidUser</managed-beanname>
<managed-beanclass>
net.roseindia.web.ui.CheckValidUser</
managed-bean-class>
<managed-bean-scope>session
</managed-bean-scope>
</managed-bean>

4. Integrating JSF with business logic tier
We are using ServiceFinder class to get the Spring managed bean.

FacesContext context=
FacesContext.getCurrentInstance();
ServletContext servletContext =
(ServletContext)context.getExternalContext().
getContext();
ApplicationContext appContext =
WebApplicationContextUtils.
getWebApplicationContext(servletContext);

11. Integrating Business Logic Tier and
Integration Tier Components In the business logic tier web have created business objects, business services and now we are going to integrate them using Spring
framework.

Business Objects
In this example we have only one business object the User.

Integration tier components

Hibernate maps the business objects to database using XML configuration file. Following file (User.hbm.xml) is used to map User object with the database.

<?xml version=”1.0" encoding=”UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC “-//
Hibernate/Hibernate Mapping DTD//EN”
”http://hibernate.sourceforge.net/hibernatemapping-
3.0.dtd”>

 

<hibernate-mapping auto-import=”true”
default-lazy=”false”>
<class
name=”net.roseindia.dao.hibernate.User”
table=”users”>
<id
name=”userId”
type=”java.lang.Integer”
column=”userId”>
<generator class=”increment” />
</id>
<property
name=”userName”
type=”java.lang.String”
column=”userName”
length=”20"/>
<property
name=”userPassword”
type=”java.lang.String”
column=”userPassword”
length=”11"/>
<property
name=”userEmail”
type=”java.lang.String”
column=”userEmail”
length=”30" />
<property
name=”userAddress”
type=”java.lang.String”
column=”userAddress”
length=”30"/>
<!— Associations —>
</class>
</hibernate-mapping>

The HibernateSpringDAO is wired with HibernateTemplate by Spring:

<bean id=”HibernateSpringDaoTarget”
class=”net.roseindia.dao.HibernateSpringDAOImpl”>
<property name=”sessionFactory”><ref
local=”sessionFactory”/></property>
</bean>

Jan 2008 | Java Jazz Up | 73
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

83, 84 , 85 , 86, 87 , 88, 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103, 104 , 105 ,

106, 107,

Download PDF