Magazine
 
Integrating JSF, Spring and Hibernate
 

Here is the code of
HibernateSpringDAOImpl.java file that

actually implements the logic:

package net.roseindia.dao;
import java.util.*;
import
org.springframework.dao.DataAccessException;
import
org.springframework.orm.hibernate3.
support.HibernateDaoSupport;
import org.hibernate.criterion.*;
//Java Imports
import java.sql.*;
import javax.servlet.http.HttpSession;
//Project Imports
import net.roseindia.dao.hibernate.*;
public class HibernateSpringDAOImpl
extends HibernateDaoSupport
implements HibernateSpringDAO {
public User checkUser(String strUserName)
throws DataAccessException,
java.sql.SQLException {
User obj = null;
DetachedCriteria criteria =
DetachedCriteria.forClass(User.class);
criteria.add(Expression.eq(“userName”,
strUserName));
List objs =
getHibernateTemplate().findByCriteria(criteria);
if ((objs != null) && (objs.size() > 0)) {
obj = (User) objs.get(0);
}
return obj;
}
public User validateUser(String
strUserName,String password)
throws DataAccessException,
java.sql.SQLException {
User obj = null;
DetachedCriteria criteria =
DetachedCriteria.forClass(User.class);
criteria.add(Expression.eq(“userName”,
strUserName));

 

criteria.add(Expression.eq(“userPassword”,
password));
List objs =
getHibernateTemplate().findByCriteria(criteria);
if ((objs != null) && (objs.size() > 0)) {
obj = (User) objs.get(0);
}
return obj;
}
public void
addUser(net.roseindia.dao.hibernate.User
obj)
throws DataAccessException {
getHibernateTemplate().save(obj);
} };

Database Design
Our application contains only one table whose structure is as follows:

In the next section we will integrate all the
components.

9. Integrating JSF, Spring and Hibernate
In this section we will explain you the process of Integrating Spring with JSF technology. This section gives you a brief description about Spring container (a WebApplicationContext), which contains all the ‘business beans’ present in the application.

Configuring Spring context(WebApplicationContext)

What is WebApplicationContext?
The WebApplicationContext is an interface that extends the ApplicationContext interface in the Spring framework. This interface is used to provide the configuration for a web application. The WebApplicationContext is ready only while application is running, it can even be reloaded in runtime if the implementation supports this.

 

Jan 2008 | Java Jazz Up | 70
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