JSF 2.0 + Spring + Hibernate integration example

Here’s a long article to show you how to integrate JSF 2.0, Spring and Hibernate together. At the end of the article, you will create a page which display a list of the existing customer from database and a “add customer” function to allow user to add a new customer into database.

P.S In this example, we are using MySQL database and deploy to Tomcat 6 web container.

1. Project Structure

Directory structure of this example

jsf2-spring-hibernate-folder-1
jsf2-spring-hibernate-folder-2

2. Table Script

Create a customer table and insert 2 dummy records.


DROP TABLE IF EXISTS `mkyongdb`.`customer`;
CREATE TABLE  `mkyongdb`.`customer` (
  `CUSTOMER_ID` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `NAME` varchar(45) NOT NULL,
  `ADDRESS` varchar(255) NOT NULL,
  `CREATED_DATE` datetime NOT NULL,
  PRIMARY KEY (`CUSTOMER_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;

insert into mkyongdb.customer(customer_id, name, address, created_date)
values(1, 'mkyong1', 'address1', now());
insert into mkyongdb.customer(customer_id, name, address, created_date)
values(2, 'mkyong2', 'address2', now());

3. Hibernate Stuff

A model class and Hibernate mapping file for customer table.

File : Customer.java


package com.mkyong.customer.model;

import java.util.Date;

public class Customer{
	
	public long customerId;
	public String name;
	public String address;
	public Date createdDate;
	
	//getter and setter methods
	
}

File : Customer.hbm.xml


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.mkyong.customer.model.Customer" 
        table="customer" catalog="mkyongdb">
 
        <id name="customerId" type="long">
            <column name="CUSTOMER_ID" />
            <generator class="identity" />
        </id>
        <property name="name" type="string">
            <column name="NAME" length="45" not-null="true" />
        </property>
        <property name="address" type="string">
            <column name="ADDRESS" not-null="true" />
        </property>
        <property name="createdDate" type="timestamp">
            <column name="CREATED_DATE" length="19" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

4. Spring Stuff

Spring’s BO and DAO classes for business logic and database interaction.

File : CustomerBo.java


package com.mkyong.customer.bo;
 
import java.util.List;
 
import com.mkyong.customer.model.Customer;
 
public interface CustomerBo{
 
	void addCustomer(Customer customer);
 
	List<Customer> findAllCustomer();
 
}

File : CustomerBoImpl.java


package com.mkyong.customer.bo.impl;
 
import java.util.List;
import com.mkyong.customer.bo.CustomerBo;
import com.mkyong.customer.dao.CustomerDao;
import com.mkyong.customer.model.Customer;
 
public class CustomerBoImpl implements CustomerBo{
 
	CustomerDao customerDao;
 
	public void setCustomerDao(CustomerDao customerDao) {
		this.customerDao = customerDao;
	}
 
	public void addCustomer(Customer customer){
 
		customerDao.addCustomer(customer);
 
	}
 
	public List<Customer> findAllCustomer(){
 
		return customerDao.findAllCustomer();
	}
}

File : CustomerDao.java


package com.mkyong.customer.dao;
 
import java.util.List;
 
import com.mkyong.customer.model.Customer;
 
public interface CustomerDao{
 
	void addCustomer(Customer customer);
 
	List<Customer> findAllCustomer();
 
}

File : CustomerDaoImpl.java


package com.mkyong.customer.dao.impl;
 
import java.util.Date;
import java.util.List;
 
import com.mkyong.customer.dao.CustomerDao;
import com.mkyong.customer.model.Customer;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
 
public class CustomerDaoImpl extends 
       HibernateDaoSupport implements CustomerDao{
 
	public void addCustomer(Customer customer){
 
		customer.setCreatedDate(new Date());
		getHibernateTemplate().save(customer);
 
	}
 
	public List<Customer> findAllCustomer(){
 
		return getHibernateTemplate().find("from Customer");
 
	}
}

File : CustomerBean.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
   	<bean id="customerBo" 
         class="com.mkyong.customer.bo.impl.CustomerBoImpl" >
   		<property name="customerDao" ref="customerDao" />
   	</bean>
 
   	<bean id="customerDao" 
         class="com.mkyong.customer.dao.impl.CustomerDaoImpl" >
   		<property name="sessionFactory" ref="sessionFactory" />
   	</bean>
 
</beans>

5. Spring + Database

Configure database detail in Spring.

File : db.properties


jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mkyongdb
jdbc.username=root
jdbc.password=password

File : DataSource.xml


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
 <bean 
   class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="location">
		<value>WEB-INF/classes/config/database/db.properties</value>
   </property>
</bean>
 
  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
	<property name="driverClassName" value="${jdbc.driverClassName}" />
	<property name="url" value="${jdbc.url}" />
	<property name="username" value="${jdbc.username}" />
	<property name="password" value="${jdbc.password}" />
  </bean>
 
</beans>

6. Spring + Hibernate

Integrate Hibernate and Spring via LocalSessionFactoryBean.

File : HibernateSessionFactory.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
<!-- Hibernate session factory -->
<bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
 
    <property name="dataSource">
      <ref bean="dataSource"/>
    </property>
 
    <property name="hibernateProperties">
       <props>
         <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
         <prop key="hibernate.show_sql">true</prop>
       </props>
    </property>
 
    <property name="mappingResources">
	<list>
          <value>com/mkyong/customer/hibernate/Customer.hbm.xml</value>
	</list>
     </property>	
 
</bean>
</beans>

7. JSF 2.0

JSF managed bean to call Spring’s BO to add or get customer’s records from database.

File : CustomerBean.java


package com.mkyong;

import java.io.Serializable;
import java.util.List;

import com.mkyong.customer.bo.CustomerBo;
import com.mkyong.customer.model.Customer;

public class CustomerBean implements Serializable{
 
	//DI via Spring
	CustomerBo customerBo;
	
	public String name;
	public String address;
	//getter and setter methods

	public void setCustomerBo(CustomerBo customerBo) {
		this.customerBo = customerBo;
	}
 
	//get all customer data from database
	public List<Customer> getCustomerList(){
		return customerBo.findAllCustomer();
	}
	
	//add a new customer data into database
	public String addCustomer(){
		
		Customer cust = new Customer();
		cust.setName(getName());
		cust.setAddress(getAddress());
		
		customerBo.addCustomer(cust);
		
		clearForm();
		
		return "";
	}
	
	//clear form values
	private void clearForm(){
		setName("");
		setAddress("");
	}
	
}

A JSF page to display existing customer records via h:dataTable and a few text components to allow user to insert new customer record into database.

File : default.xhtml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"   
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      >
    <h:head>
    	<h:outputStylesheet library="css" name="table-style.css"  />
    </h:head>
 
    <h:body>
 
    	<h1>JSF 2.0 + Spring + Hibernate Example</h1>
 
 		<h:dataTable value="#{customer.getCustomerList()}" var="c"
    			styleClass="order-table"
    			headerClass="order-table-header"
    			rowClasses="order-table-odd-row,order-table-even-row"
    		>
 
    		<h:column>
    			<f:facet name="header">
    				Customer ID
    			</f:facet>
    				#{c.customerId}
    		</h:column>
 
    		<h:column>
    			<f:facet name="header">
    				Name
				</f:facet>
    				#{c.name}
    		</h:column>
 
 			<h:column>
    			<f:facet name="header">
    				Address
				</f:facet>
    				#{c.address}
    		</h:column>
    		
    		<h:column>
    			<f:facet name="header">
    				Created Date
				</f:facet>
    				#{c.createdDate}
    		</h:column>
    		
    	</h:dataTable>
 		
 		<h2>Add New Customer</h2>
 		<h:form>
 			
 			<h:panelGrid columns="3">
			
				Name : 
				<h:inputText id="name" value="#{customer.name}" 
					size="20" required="true"
					label="Name" >
				</h:inputText>
					
				<h:message for="name" style="color:red" />
			
				Address : 
				<h:inputTextarea id="address" value="#{customer.address}" 
					cols="30" rows="10" required="true"
					label="Address" >
				</h:inputTextarea>
					
				<h:message for="address" style="color:red" />
				
			</h:panelGrid>
			
			<h:commandButton value="Submit" action="#{customer.addCustomer()}" />

 		</h:form>
 		
    </h:body>
 
</html>

8. JSF 2.0 + Spring

Integrate JSF 2.0 with Spring, see detail explanation here – JSF 2.0 + Spring integration example

File : applicationContext.xml


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
	<!-- Database Configuration -->
	<import resource="classes/config/spring/beans/DataSource.xml"/>
	<import resource="classes/config/spring/beans/HibernateSessionFactory.xml"/>
 
	<!-- Beans Declaration -->
	<import resource="classes/com/mkyong/customer/spring/CustomerBean.xml"/>
 
</beans>

File : faces-config.xml


<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">
 
	<application>
    	<el-resolver>
    		org.springframework.web.jsf.el.SpringBeanFacesELResolver
    	</el-resolver>
  	</application>
 	
	<managed-bean>
		<managed-bean-name>customer</managed-bean-name>
		<managed-bean-class>com.mkyong.CustomerBean</managed-bean-class>
		<managed-bean-scope>session</managed-bean-scope>
		<managed-property>
			<property-name>customerBo</property-name>
			<value>#{customerBo}</value>
		</managed-property>
	</managed-bean>
 
</faces-config>

File : web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
	id="WebApp_ID" version="2.5">
 
  <display-name>JavaServerFaces</display-name>

  <!-- Add Support for Spring -->
  <listener>
	<listener-class>
		org.springframework.web.context.ContextLoaderListener
	</listener-class>
  </listener>
  <listener>
	<listener-class>
		org.springframework.web.context.request.RequestContextListener
	</listener-class>
  </listener>

  <!-- Change to "Production" when you are ready to deploy -->
  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
  </context-param>
 
  <!-- Welcome page -->
  <welcome-file-list>
    <welcome-file>faces/default.xhtml</welcome-file>
  </welcome-file-list>
 
  <!-- JSF mapping -->
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
 
  <!-- Map these files with JSF -->
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
 
</web-app>

9. Demo

Run it, fill in the customer data and click on the “submit” button.

jsf2-spring-hibernate-example-1
jsf2-spring-hibernate-example-2

Download Source Code

Reference

  1. JSF 2.0 + Spring integration example
  2. Struts + Spring + Hibernate integration example
author image

mkyong

Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities. Read all published posts by

Comments

avatar
125 Comment threads
94 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
141 Comment authors
szaroblekitnyMr_djay619shailesh pathakjonCharles Recent comment authors
newest oldest most voted
trackback
JSF 2.0 + Spring + Hibernate integration example

[…] a list of the existing customer from database and a “add customer” function to… [full post] mkyong Mkyong Dot Com hibernatejsf2spring 0 0 0 0 0 […]

Hugo Tota
Guest
Hugo Tota

JSF 2, Hibernate and Spring with xml configuration? interesting choice

ahmet
Guest
ahmet

Hi,
I am using Spring and Hibernate in my Jsf 2.* project, but I got a problem. I can’t make it to navigate from one page to another. I did the configuration as you mentioned above, but when I return the name of the page that is wanted to be redirected, it does nothing. Could you help me about this problem. Thanks…

long nguyen
Guest
long nguyen

i have downloaded your project and import it to run on Eclipse.
But i have the following errors:

Caused by: java.lang.NoClassDefFoundError: org/objectweb/asm/Type
	at net.sf.cglib.core.TypeUtils.parseType(TypeUtils.java:180)
	at net.sf.cglib.core.KeyFactory.(KeyFactory.java:66)
	at net.sf.cglib.proxy.Enhancer.(Enhancer.java:69)
	at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)
	at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:188)
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.(AbstractEntityTuplizer.java:128)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.(PojoEntityTuplizer.java:78)
	... 48 more
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
	... 56 more

I think it miss asm library, but i have add asm library dependency to pom.xml as below:

asm
asm
3.1

but it still not working, plz help me!
Thanks you in advance!

Here my project http://www.mediafire.com/file/176c3q1il1cja52/JSF-2-Spring-Hibernate-Integration-Example__error.rar

long nguyen
Guest
long nguyen

Hi mkyong, today when I restart my computer and eclipse, your example has worked properly.
Thanks for your good tutorial.

long nguyen
Guest
long nguyen

Hi mkyong, Depend on your tutorial I have tried to integrate JSF(2.0) + SPRING(2.5) + HIBERNATE(3) in my way! Here is my directory structor: Here is mydatabase script — — Table structure for table `account` — CREATE TABLE IF NOT EXISTS `account` ( `id` int(11) NOT NULL auto_increment, `name` varchar(40) character set utf8 collate utf8_unicode_ci NOT NULL, `pass` varchar(40) character set utf8 collate utf8_unicode_ci NOT NULL, `email` varchar(40) character set utf8 collate utf8_unicode_ci NOT NULL, `datecreated` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; — — Dumping data for table `account` — INSERT INTO `account` (`id`,… Read more »

long nguyen
Guest
long nguyen

I didn’t use maven to manage dependency, instead I copy all dependency library to /WEB-INF/lib. So my project too large. And here my project http://www.mediafire.com/?ie9eiey1f2y1alr

long nguyen
Guest
long nguyen

I have fixed it. I added these libs: jsp-api.jar, el-api-2.2.jar, el-impl-2.2.jar
to WEB-INF/lib folder.
It’s work!
Thank you mkyong!

trackback
Linki do stron: spring + jsf 2.0 + hibernate « Robocze notatki

[…] http://www.mkyong.com/jsf2/jsf-2-0-spring-hibernate-integration-example/ LikeBe the first to like this post. […]

Angel
Guest
Angel

I am working on a JSF application using spring/Ibatis;
database is MSSQL; On a table I have a datefield;
NULL allowed;

When I fill a form I pick the date (Rich:calendar) datePattern yy/MM/dd HH:mm;
With “DATE” inline parameter the hour & minutes do not save to database;
without the “DATE” inline parameter; I cannot accept null values for dates

ANyone has a solution

Angel
Guest
Angel

Ibatis/JSF/Spring;
rich:calendar

Having a problem…

When I use “DATE” inline parameter, the hour minute does NOT save to MSsql database – but can accept null values;
When I do NOT use the “DATE” inline parameter, the hour minute saves, but cannot accept null values

Suggestions?

David
Guest
David

Hi Mkyong,

I tried your tutorial using eclipse, instead use mysql I use oracle as backend DB.
when I start tomcat server I got following java.lang.ClassCastException:
java.lang.ClassCastException: javax.faces.webapp.FacesServlet cannot be cast to javax.servlet.Servlet.

any ideas to fix this?

thanks in advance

David

Arslan
Guest
Arslan

Hi,
I tried this tutorial, everythings works fine in eclipse, but when i package it and deploy to comcat, it gives the error:

Contect initialization failed,
Error creating the bean with name ‘seesionFactory’ defined in ServletContext response.

Please help me.. looking forward for your response…

Bhushan
Guest
Bhushan

Hi,

I am running your project as it is. And i am getting the error in CustomerDaoImpl.java at public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao{ .

It says ‘inconsistent hierarchy’ at this ‘extends’.

I am using Eclipse Helio. Any idea?

Thanks.

Mario
Guest
Mario

I am having same problem now… did u fixed it??

Thanks!
Mario

Harry
Guest
Harry

Hi Yong,

I am trying to run your example but I am getting below error. What could be the problem

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘customerDao’ defined in ServletContext resource [/WEB-INF/classes/com/mkyong/customer/spring/CustomerBean.xml]: Cannot resolve reference to bean ‘sessionFactory’ while setting bean property ‘sessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in ServletContext resource [/WEB-INF/classes/config/spring/beans/HibernateSessionFactory.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

lightstar41
Guest
lightstar41

Thanks for sharing, it is fine!
Struct is very clear, easier to learn

lightstar41
Guest
lightstar41

Work done,
but in default.xhtml:
at “#{customer.getCustomerList()}” line get error:
————————————————-
Multiple annotations found at this line:
– Syntax error in EL
– Expression must be a value expression but is a method
expression
————————————————-

Any idea?

Mario
Guest
Mario

Hi Mkyong,
Can you post this example by Annotaion ?
Bye Mario

lightstar41
Guest
lightstar41

Hi mkyong, nice to meet you again!

Can you post the modiffed source code which:

1.Use JSF
2.Use Spring controller with annotation(without CustomerBean.java
)

many thanks

Anil
Guest
Anil

What is the difference between bean created in faces-config.xml(JSF beans) and application-context.xml(Spring Bean)? Both act same or what?

Thanks
Anil

Anil
Guest
Anil

I mean , Is it ok if i use spring bean like JSF bean(created in faces-config.xml) at the JSF page.

Thanks
Anil

Angel
Guest
Angel

Do you have a good example on Database pagination that you could share!

SpringLearner
Guest
SpringLearner

Hi,

Your sample is fantastic and easy to learn.
I am new to Spring,Hibernate and JSF.
Please help me in resolving the issue.
I tried to run your given sample in Netbeans 7.0 and glass fish server 3.1. I can build the sample successfully but on Run it throws exceptions as below:

In-place deployment at C:\Documents and Settings\abc\Desktop\Spring JSP Hibernate\JavaServerFaces\target\JavaServerFaces
deploy?config=file%3A%2FC%3A%2FDOCUME%7E1%2Fabc%2FLOCALS%7E1%2FTemp%2Fcontext13479.xml&path=/JavaServerFaces
FAIL - Deployed application at context path /JavaServerFaces but context failed to start
The module has not been deployed.
	at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:187)
	at org.netbeans.modules.maven.j2ee.ExecutionChecker.performDeploy(ExecutionChecker.java:167)
	at org.netbeans.modules.maven.j2ee.ExecutionChecker.executionResult(ExecutionChecker.java:123)
	at org.netbeans.modules.maven.execute.MavenCommandLineExecutor.run(MavenCommandLineExecutor.java:208)
	at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:154)
softocean
Guest
softocean

Hei,

I am trying this spring + hibernate example using postgreSQL database. I got the following error when i run this example.

Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(I)V
	at net.sf.cglib.core.DebuggingClassWriter.(DebuggingClassWriter.java:47)
	at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)
	at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
	at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
	at net.sf.cglib.proxy.Enhancer.(Enhancer.java:69)
	at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)
	at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:188)
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.(AbstractEntityTuplizer.java:128)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.(PojoEntityTuplizer.java:78)
	... 57 more

Any helpful comments will be appreciate.

Chak
Guest
Chak

Encountered the same problem.

I changed the dependencies from cglib 2.2 to cglib 2.1 and it works.

Aurore
Guest
Aurore

Hi All,

it’s a good example. However, i encounter the same problem and even if i change cglib from 2.2 to 2.1, it’s still not working. Can you give me another peice of advice?

Many Thanks

Anil
Guest
Anil

Hi, Nice article on the integration of frameworks.I have a small issue, i just modified the code for my requirements to show the all the customers in a drop-down list.I placed the h:selectOneMenu and i populate the f:selectItems with the list of customerBean. It is showing the correct values in the front but, when i select one value the whole list (all f:selectItems) is showing as selected.And in the log i found that for every selectItem a hibernate call is going.I mean if i have 4 items then there will be 4 calls to the hibernate to retrieve the list.Could… Read more »

Mohamed
Guest
Mohamed

Salam ,

Plz can u make an example ” How to use session in a JSF Project ” ?

if the visitor not logged , it will be redirected to the login page …

Mario
Guest
Mario

Hi All,

I have been trying to execute this example, but i think i dont have the right jars… everything seems to be fine in Eclipse but in CustomerDaoImpl.java it gives me this error The import org.springframework.orm.hibernate3.support.HibernateDaoSupport cannot be resolved

Do you know how can i fix it ??

Thanks a lot!
Mario Abundis

Mario
Guest
Mario

I have added this two jars:
spring-hibernate3.jar
spring-tx-2.5.6.jar

And know it can find the HibernateDaoSupport, but now is giving me this errors:

public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao{

It says for CustomerDaoImpl : The hierarchy of the type CustomerDaoImpl is inconsistent

And for HibernateDaoSupport: The type org.springframework.beans.factory.InitializingBean cannot be resolved. It is indirectly referenced from required .class files

Do you guys have an idea what could be the problem??

Thanks
Mario Abundis

Shailendra kumar
Guest
Shailendra kumar

For people facing this error in Eclipse “CustomerDaoImpl.java – The import org.springframework.orm.hibernate3.support.HibernateDaoSupport cannot be resolved”, please include the below lines in the dependency in pom.xml


		org.springframework
		spring-orm
		2.5.6
	
Shailendra kumar
Guest
Shailendra kumar

Sorry I meant

		org.springframework
		spring-orm
		2.5.6
	
Anu
Guest
Anu

Hi Mkyong,
I am trying to create and build a project similar to your example. I am using oracle database, i am not able to view default.xhtml file on the site.. could you please help me in creating this project..

Looking forward….

Anu
Guest
Anu

Getting following error:

Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletRequestListener
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
	... 25 more
Anu
Guest
Anu

Hi Mkyong,

I created dynamic web project and included all libs into lib folder. i am using eclipse helios, jdk1.6, tomcat 7 to run the application. when i start the server, i am not getting any error in the console but in the browser it dispays
Page cannot be displayed.

Please let me know what mistake i have done..

ramesh
Guest
ramesh

one great thanks to yong, the code was perfect, with certain jars needed to be modified. but finally i could able run, and understand the basics.

Thanks
Ramesh

krunal
Guest
krunal

hi mkyong,

Thankyou very much for this begineer tutorial,

It is very helpful.
but can you explain the flow of application in this example

ram
Guest
ram

Hi Master,

Need to know how update a row in datable. I tried your code and it doesn’t work can I post it what’s wrong with it ?

Advanced thanks
@+ ram

JSTROSH
Guest
JSTROSH

Hello mkyong,

this was brilliant example and i was able to run it locally..

I had one question regarding transaction… How is the transaction getting started in above example as i do not see any transaction related information in the xml config files ?