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

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

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
szaroblekitny
Guest
szaroblekitny

Most of this stuff is deprecated now. Maybe it is worth considering to update? It would be nice ;-)

Mr_djay619
Guest
Mr_djay619

there are lack of some dependencies in pom.xml file in this example

shailesh pathak
Guest
shailesh pathak

Hi, Nice and clear tutorial. I am facing issue while launching it with Glassfish and H2 database.

java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘dataSource’ defined in ServletContext resource [/WEB-INF/classes/config/spring/beans/DataSource.xml]: Error setting property values; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property ‘connection’ of bean class [org.springframework.jdbc.datasource.DriverManagerDataSource]: Getter for property ‘connection’ threw exception; nested exception is java.lang.reflect.InvocationTargetException

here is how I have mention bean tag in DataSource.xml

Please let me know in case I am missing anything

Charles
Guest
Charles

Project is not running (01/10/2015) because of old dependencies. – Follow the 3 steps to make the build and application deployement running – 1 – please add jta dependency : javax.transaction jta 1.1 2 – please add asm dependency because of SessionFactory exception in initialization context : asm asm 3.1 3 – Modify hibernate dependency declaration and add this : org.hibernate hibernate 3.2.7.ga asm asm asm asm-attrs

shareef
Guest
shareef

i had problems and exceptions … see all experince in the tutorial http://stackoverflow.com/questions/19086523/missing-artifact-javax-transactionjtajar1-0-1b-issue-was-different-as-you-m/31347138#31347138

ON GITHUB https://github.com/shareefhiasat/mkyong tested on spring tools sts Spring Tool Suite

Version: 3.7.0.RELEASE
Build Id: 201506290652
Platform: Eclipse Mars (4.5.0)

facilus
Guest
facilus

hi mkyong, it’s works very fine.

i’m trying to change the mapping with annotation (not with hbm file), i’ve this error in hql :

nested exception is org.hibernate.hql.ast.QuerySyntaxException: Customer is not mapped

Tomek
Guest
Tomek

Have anyone met and resolved such a problem when adding a new item? I’ve spent quite a long time trying to figure out how to solve such problem.

SEVERE: java.lang.ClassCastException: com.zzz.item.model.Item cannot be cast to java.util.Map
javax.faces.el.EvaluationException: java.lang.ClassCastException: com.zzz.item.model.Item cannot be cast to java.util.Map
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
at javax.faces.component.UICommand.broadcast(UICommand.java:311)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1255)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)

kalyani
Guest
kalyani

I tried this example but if i run this app in server it is searching for .jsp file not accepting .xhtml file here is my web.xml file JavaServerFaces org.springframework.web.context.ContextLoaderListener org.springframework.web.context.request.RequestContextListener javax.faces.PROJECT_STAGE Development default.xhtml Faces Servlet javax.faces.webapp.FacesServlet 1 Faces Servlet /faces/* Faces Servlet *.jsf Faces Servlet *.faces Faces Servlet *.xhtml

facilus
Guest
facilus

How to add composite entity in jsf and hibernate ?
For exemple if Customer contains ‘idStore’ , (Store contains idStore and libelleStore)

in jsf, what is instruction to display libelleStore from customer ?
in hibernate, how load the object Store when find Costumer ?

facilus
Guest
facilus

Thank’s for your example. I’ve this error when i try to add new Customer : Caused by: java.lang.ClassCastException: com.faycal.customer.model.Customer cannot be cast to java.util.Map at org.hibernate.property.MapAccessor$MapGetter.get(MapAccessor.java:67) at org.hibernate.property.MapAccessor$MapGetter.getForInsert(MapAccessor.java:71) at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValuesToInsert(AbstractEntityTuplizer.java:264) at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValuesToInsert(AbstractEntityPersister.java:3647) at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:267) at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187) at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172) at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70) at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:536) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:524) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:520) at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:697) at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419) at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:694) at com.faycal.customer.dao.impl.CustomerDaoImpl.addCustomer(CustomerDaoImpl.java:16) at com.faycal.customer.bo.impl.CustomerBoImpl.addCustomer(CustomerBoImpl.java:18) at com.faycal.customer.CustomerBean.addCustomer(CustomerBean.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.el.parser.AstValue.invoke(AstValue.java:278) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84) … 28 more

Mimi
Guest
Mimi

Do you find the problem pleaseee ?
I’m blocked !

Tomek
Guest
Tomek

Have you found any solution for such problem? I’m struggling with this too.

facilus
Guest
facilus

Yes, i resolve a problem

i update a lot of source, like exclude some jar and adding others

org.hibernate

hibernate

3.2.7.ga

asm

asm

asm

asm-attrs

Ajay Kumar
Guest
Ajay Kumar

where to find all jars for the above post.

rt
Guest
rt

i`m getting the same error … does anybody know how to fix it?

AAM Soukaina
Guest
AAM Soukaina

Thanks alot for this very clever tutorial, I tried to add “delete modify” but unfortunately I can not achieve, if possible you could help me.

Ibrahim Samadi
Guest
Ibrahim Samadi

Hi ,
thank you for this tutorial,
I want to add Primefaces but it does not work I do not know if it’s a version problem I used primeface 3.5, if you can help me plzz

pchoucine
Guest
pchoucine

thinks

if he treats this video perfectly integration between spring, jsf and hibernate.

https://www.youtube.com/watch?v=XHu541F_yOo

jk
Guest
jk

hhh

Deepika Sharma
Guest
Deepika Sharma

How does this applicationContext.xml gets loaded in Spring container. Does ContextLoaderListener load it?

Zia
Guest
Zia

Thanks a lot mkyong for the nice tutorial. I can run it without any problem on tomcat 6 but if I run on tomcat 7 then I get the following errors:

java.lang.ClassNotFoundException: javax.servlet.ServletContextListener

java.lang.ClassNotFoundException: javax.servlet.ServletRequestListener

I am really want to know the reason behind that. Is there any major difference between tomcat 6 and 7 in this context?

Any clue will be highly appreciated.

Best Regards

trackback
Spring + Hibernate + JSF + Primeface Intergration Project |

[…] 2. http://www.mkyong.com/jsf2/jsf-2-0-spring-hibernate-integration-example/ […]

trackback
Spring + Hibernate + JSF + Primeface Intergration Project | VN.NVANHUONG

[…] 2. http://www.mkyong.com/jsf2/jsf-2-0-spring-hibernate-integration-example/ […]

Zeeshan Akhter
Guest
Zeeshan Akhter

when you will fix that tutorial ….. you should post properly function tutorials with updated pom.xml just look that pom.xml its very old and due to that, ur tutorial is not working and its useless. plz quickly update that ……………

enderwiggin
Guest
enderwiggin

i’m getting an error when i’m trying to add a customer: it crash down at the line of code that is this: getHibernateTemplate().save(customer); in the method public void addCustomer(Customer customer) { customer.setCreatedDate(new Date()); getHibernateTemplate().save(customer); } in the class CustomerDaoImpl in the package: com.mkyong.customer.dao.impl I don’t know why it’s trying to cast java.util.Map; but the most baffling it’s that the error seems to be that it comes from server faces (javax.faces.el.EvaluationException), that would be comprehensible but i have make a little test by commenting the line: getHibernateTemplate().save(customer); the result of the test was that le application goes well, it didn’t add… Read more »

ender
Guest
ender

thanks very much by such usefull information

Divya
Guest
Divya

This is a grate tutorial.Can you please explain a JSF+Hibernate application in JDeveloper IDE?

kannan
Guest
kannan

Hi 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] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4521) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5004) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:4999) at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer] at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:110) at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:135) at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.(EntityEntityModeToTuplizerMapping.java:56) at org.hibernate.tuple.entity.EntityMetamodel.(EntityMetamodel.java:323) at… Read more »

Evelyn
Guest
Evelyn

yo resolvi el pojo tuplizer:
+cambiando en Customer.hbm.xml….
“name” por “entity-name”

Pepito
Guest
Pepito

@Evelyn: Claro que si

Said
Guest
Said

Thank you very much Evelyn

Evelyne
Guest
Evelyne

Hello Kannan,

I have the same message :
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

Did you find a solution to this problem ?
Best regards.

Paj@k
Guest
Paj@k

Hi Evelyn,

try this:

3.1.0.RELEASE
3.2.7.ga
3.1

org.hibernate
hibernate
${hibernate.version}

asm
asm

asm
asm-attrs

asm
asm
${asm.version}

For me this solution helped.

Said
Guest
Said

the solution is to replace “name” by “entity-name” in the file Customer.hbm.xml

Katherine R.
Guest
Katherine R.

I had the same “Tuple” error. I put these dependencies into my pom.xml file (per StackOverflow) and the problem resolved itself:

org.hibernate
hibernate
3.2.7.ga

asm
asm

asm
asm-attrs

asm
asm
3.1

Sid
Guest
Sid

Awesome .. that works!

Johnnie Skywalker
Guest
Johnnie Skywalker

actually groupId instead of groupid and artifactId instead of artifactid. Anyway it doesn’t solve this error in my project :'(

Saw John Linn
Guest
Saw John Linn

Dear Mr.Mkyong and friends.

I am ok in developing and running this sample. But I found one bug. It is…

Every pressing “F5” or “Refresh”, It was automatically inserted the previous row.
Why it is?. I have change scope in faces-config.xml “session” to “request” but nothing special. Any can help me?

Thanks.
Saw John Linn
United Arakan Kingdom

Thuận
Guest
Thuận

In file CustomerDAOImpl.java, there are an error such as:
Multiple markers at this line
– The type org.springframework.dao.support.DaoSupport cannot be resolved. It is indirectly referenced from
required .class files
– The hierarchy of the type CustomerDAOImpl is inconsistent

Please, help me. Thanks all.

jon
Guest
jon

got the same error. have you found a solution?

ouechTonton
Guest
ouechTonton

Thanks a lot for this very clever tutorial

Md.Alauddin Hossain
Guest
Md.Alauddin Hossain

What I can do for the compiling error “The import org.springframework.orm.hibernate3.support.HibernateDaoSupport can’t be resolved”.I have tried using spring-orm.jar and hibernet-3.3.2-ga.jar.

Can you please inform me how to resolve this issue?

psatyani
Guest
psatyani

Try making an Object of HibernateDaoSupport object like :

HibernateDaoSupport hd=new HibernateDaoSupport() {};

and

then add

return hd.getHibernateTemplate().find(“from Customer”);

Maciej
Guest
Maciej

When I follow this tutorial and I call Dao in @PostConstruct i get
org.hibernate.HibernateException: No Session found for current thread
Do you know how to solve it?