Struts 2 + Hibernate integration example

In Struts2, there are no official plugins to integrate the Hibernate framework. But, you can workaround with the following steps :

  1. Register a custom ServletContextListener.
  2. In the ServletContextListener class, initialize the Hibernate session and store it into the servlet context.
  3. In action class, get the Hibernate session from the servlet context, and perform the Hibernate task as normal.

See the relationship :

Struts 2 <-- (Servlet Context) ---> Hibernate <-----> Database

In this tutorial, it shows a simple customer module (add and list function), developed in Struts 2, and perform the database operation with Hibernate. The integration part is using the above stated mechanism (store and retrieve the Hibernate session in the servlet context).

This workaround is very similar with the classic Struts 1.x and Hibernate integration, just the classic Struts 1.x is using the Struts’s plugins; While the Struts 2 is using the generic servlet listener.

1. Project structure

See this full project folder structure.

Struts 2 Hibernate integration example

2. MySQL table script

Create a customer table for the demonstration. Here’s the SQL table script.

DROP TABLE IF EXISTS `mkyong`.`customer`;
CREATE TABLE  `mkyong`.`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;

3. Dependency

Get the Struts2, Hibernate and MySQL dependency libraries.

//...
	<!-- Struts 2 -->
	<dependency>
	        <groupId>org.apache.struts</groupId>
		<artifactId>struts2-core</artifactId>
		<version>2.1.8</version>
        </dependency>
 
	<!-- MySQL database driver -->
	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<version>5.1.9</version>
	</dependency>
 
	<!-- Hibernate core -->
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate</artifactId>
		<version>3.2.7.ga</version>
	</dependency>
 
	<!-- Hibernate core library dependency start -->
	<dependency>
		<groupId>dom4j</groupId>
		<artifactId>dom4j</artifactId>
		<version>1.6.1</version>
	</dependency>
 
	<dependency>
		<groupId>commons-logging</groupId>
		<artifactId>commons-logging</artifactId>
		<version>1.1.1</version>
	</dependency>
 
	<dependency>
		<groupId>commons-collections</groupId>
		<artifactId>commons-collections</artifactId>
		<version>3.2.1</version>
	</dependency>
 
	<dependency>
		<groupId>cglib</groupId>
		<artifactId>cglib</artifactId>
		<version>2.2</version>
	</dependency>
	<!-- Hibernate core library dependency end -->
 
	<!-- Hibernate query library dependency start -->
	<dependency>
		<groupId>antlr</groupId>
		<artifactId>antlr</artifactId>
		<version>2.7.7</version>
	</dependency>
	<!-- Hibernate query library dependency end -->
//...

4. Hibernate Stuffs

The Hibernate model and configuration stuffs.

Customer.java – Create a class for customer table.

package com.mkyong.customer.model;
 
import java.util.Date;
 
public class Customer implements java.io.Serializable {
 
	private Long customerId;
	private String name;
	private String address;
	private Date createdDate;
 
	//getter and setter methods
}

Customer.hbm.xml – Hibernate mapping file for customer.

<?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="mkyong">
 
        <id name="customerId" type="java.lang.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>

hibernate.cfg.xml – Hibernate database configuration file.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
    <property name="hibernate.connection.password">password</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mkyong</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="show_sql">true</property>
    <property name="format_sql">true</property>
    <property name="use_sql_comments">false</property>
    <mapping resource="com/mkyong/customer/hibernate/Customer.hbm.xml" />
  </session-factory>
</hibernate-configuration>

5. Hibernate ServletContextListener

Create a ServletContextListener, and initialize the Hibernate session and store it into the servlet context.

HibernateListener .java

package com.mkyong.listener;
 
import java.net.URL;
 
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
 
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
 
public class HibernateListener implements ServletContextListener{
 
    private Configuration config;
    private SessionFactory factory;
    private String path = "/hibernate.cfg.xml";
    private static Class clazz = HibernateListener.class;
 
    public static final String KEY_NAME = clazz.getName();
 
	public void contextDestroyed(ServletContextEvent event) {
	  //
	}
 
	public void contextInitialized(ServletContextEvent event) {
 
	 try { 
	        URL url = HibernateListener.class.getResource(path);
	        config = new Configuration().configure(url);
	        factory = config.buildSessionFactory();
 
	        //save the Hibernate session factory into serlvet context
	        event.getServletContext().setAttribute(KEY_NAME, factory);
	  } catch (Exception e) {
	         System.out.println(e.getMessage());
	   }
	}
}

Register the listener in the web.xml file.
web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
 
<web-app>
  <display-name>Struts 2 Web Application</display-name>
 
  <filter>
	<filter-name>struts2</filter-name>
	<filter-class>
	  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
	</filter-class>
  </filter>
 
  <filter-mapping>
	<filter-name>struts2</filter-name>
	<url-pattern>/*</url-pattern>
  </filter-mapping>
 
  <listener>
    <listener-class>
	  com.mkyong.listener.HibernateListener
    </listener-class>
  </listener>
 
</web-app>

6. Action

In Action class, get the Hibernate session from the servlet context and perform the Hibernate task as normal.

CustomerAction.java

package com.mkyong.customer.action;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import org.apache.struts2.ServletActionContext;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
 
import com.mkyong.customer.model.Customer;
import com.mkyong.listener.HibernateListener;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
 
public class CustomerAction extends ActionSupport 
	implements ModelDriven{
 
	Customer customer = new Customer();
	List<Customer> customerList = new ArrayList<Customer>();
 
	public String execute() throws Exception {
		return SUCCESS;
	}
 
	public Object getModel() {
		return customer;
	}
 
	public List<Customer> getCustomerList() {
		return customerList;
	}
 
	public void setCustomerList(List<Customer> customerList) {
		this.customerList = customerList;
	}
 
	//save customer
	public String addCustomer() throws Exception{
 
		//get hibernate session from the servlet context
		SessionFactory sessionFactory = 
	         (SessionFactory) ServletActionContext.getServletContext()
                     .getAttribute(HibernateListener.KEY_NAME);
 
		Session session = sessionFactory.openSession();
 
		//save it
		customer.setCreatedDate(new Date());
 
		session.beginTransaction();
		session.save(customer);
		session.getTransaction().commit();
 
		//reload the customer list
		customerList = null;
		customerList = session.createQuery("from Customer").list();
 
		return SUCCESS;
 
	}
 
	//list all customers
	public String listCustomer() throws Exception{
 
		//get hibernate session from the servlet context
		SessionFactory sessionFactory = 
	         (SessionFactory) ServletActionContext.getServletContext()
                     .getAttribute(HibernateListener.KEY_NAME);
 
		Session session = sessionFactory.openSession();
 
		customerList = session.createQuery("from Customer").list();
 
		return SUCCESS;
 
	}	
}

7. JSP page

JSP page to add and list the customer.

customer.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>
 
<body>
<h1>Struts 2 + Hibernate integration example</h1>
 
<h2>Add Customer</h2>
<s:form action="addCustomerAction" >
  <s:textfield name="name" label="Name" value="" />
  <s:textarea name="address" label="Address" value="" cols="50" rows="5" />
  <s:submit />
</s:form>
 
<h2>All Customers</h2>
 
<s:if test="customerList.size() > 0">
<table border="1px" cellpadding="8px">
	<tr>
		<th>Customer Id</th>
		<th>Name</th>
		<th>Address</th>
		<th>Created Date</th>
	</tr>
	<s:iterator value="customerList" status="userStatus">
		<tr>
			<td><s:property value="customerId" /></td>
			<td><s:property value="name" /></td>
			<td><s:property value="address" /></td>
			<td><s:date name="createdDate" format="dd/MM/yyyy" /></td>
		</tr>
	</s:iterator>
</table>
</s:if>
<br/>
<br/>
 
</body>
</html>

8. struts.xml

Link it all ~

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
 
<struts>
  <constant name="struts.devMode" value="true" />
 
  <package name="default" namespace="/" extends="struts-default">
 
    <action name="addCustomerAction" 
	class="com.mkyong.customer.action.CustomerAction" method="addCustomer" >
       <result name="success">pages/customer.jsp</result>
    </action>
 
    <action name="listCustomerAction" 
	class="com.mkyong.customer.action.CustomerAction" method="listCustomer" >
        <result name="success">pages/customer.jsp</result>
    </action>		
 
  </package>	
</struts>

9. Demo

Access the customer module : http://localhost:8080/Struts2Example/listCustomerAction.action

Struts 2 Hibernate Add Customer

Fill in the name and address fields, hits the submit button, the inserted customer details will be listed immediately.

Struts2 Hibernate List Customer

Reference

  1. Struts 2 + Hibernate integration with “Full Hibernate Plugin”
  2. ServletContextListener documentation
  3. Struts + Hibernate integration example
Tags :

About the Author

mkyong
Founder of Mkyong.com and HostingCompass.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

  • Dibyendu sarkar

    Dependency portion I am not able to understand can you please tell me, where to add those lines and for what.

  • venky

    Iam get this error when i start the server…..application is Struts2.1 with hibernate integration

    can please send right answer

    SEVERE: Exception sending context initialized event to listener instance of class org.apache.struts2.tiles.StrutsTilesListener
    java.lang.NullPointerException
    at org.apache.commons.digester.Digester.getXMLReader(Digester.java:1058)
    at org.apache.commons.digester.Digester.parse(Digester.java:1887)
    at org.apache.tiles.definition.digester.DigesterDefinitionsReader.read(DigesterDefinitionsReader.java:267)
    at org.apache.tiles.definition.UrlDefinitionsFactory.readDefinitions(UrlDefinitionsFactory.java:286)
    at org.apache.tiles.definition.UrlDefinitionsFactory.init(UrlDefinitionsFactory.java:130)
    at org.apache.tiles.impl.BasicTilesContainer.initializeDefinitionsFactory(BasicTilesContainer.java:406)
    at org.apache.tiles.impl.BasicTilesContainer.init(BasicTilesContainer.java:130)
    at org.apache.tiles.factory.TilesContainerFactory.initializeContainer(TilesContainerFactory.java:232)
    at org.apache.tiles.factory.TilesContainerFactory.createTilesContainer(TilesContainerFactory.java:198)
    at org.apache.tiles.factory.TilesContainerFactory.createContainer(TilesContainerFactory.java:163)
    at org.apache.tiles.web.startup.TilesListener.createContainer(TilesListener.java:90)
    at org.apache.struts2.tiles.StrutsTilesListener.createContainer(StrutsTilesListener.java:68)
    at org.apache.tiles.web.startup.TilesListener.contextInitialized(TilesListener.java:57)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

  • Murat yorfun

    Hello I m a new learning javaee & struts2. I dont know lib installation. Why didnt you zip file added? Why?

    I find all internet but I dont find this “lib..”

    Please share Your lib file and I want to be relax

  • Muthu

    The issue “com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.”

    Can be resolved if we add the below dependency.

    mysql
    mysql-connector-java
    5.1.24

  • Gaurav Dighe

    Hello Sir,
    I need tutorials for below:
    1. Aware Interfaces – ApplicationAware, SessionAware, ParameterAware, ServletRequestAware and ResponseAware
    2. Interceptors – param etc..

    Regards,
    Gaurav Dighe

  • adnen

    Struts Problem Report

    Struts has detected an unhandled exception:
    Messages:

    No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error: ** BEGIN NESTED EXCEPTION ** com.mysql.jdbc.CommunicationsException MESSAGE: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE: Broken pipe STACKTRACE: java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) at java.net.SocketOutputStream.write(SocketOutputStream.java:153) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2739) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2650) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1581) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695) at com.mysql.jdbc.Connection.execSQL(Connection.java:3026) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1137) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1231) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1808) at org.hibernate.loader.Loader.doQuery(Loader.java:697) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) at org.hibernate.loader.Loader.doList(Loader.java:2228) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125) at org.hibernate.loader.Loader.list(Loader.java:2120) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:835) at eplayers.modele.MangerAnnonceModele.getAnnonceCount(MangerAnnonceModele.java:119) at eplayers.ManagerAnnonceAction.etudeChoixAnnoncejeuClassiqueORAll(ManagerAnnonceAction.java:270) at eplayers.ManagerAnnonceAction.laissePasser(ManagerAnnonceAction.java:119) at sun.reflect.GeneratedMethodAccessor117.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) ** END NESTED EXCEPTION ** Last packet sent to the server was 1 ms ago. STACKTRACE: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE: Broken pipe STACKTRACE: java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) at java.net.SocketOutputStream.write(SocketOutputStream.java:153) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2739) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2650) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1581) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695) at com.mysql.jdbc.Connection.execSQL(Connection.java:3026) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1137) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1231) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1808) at org.hibernate.loader.Loader.doQuery(Loader.java:697) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) at org.hibernate.loader.Loader.doList(Loader.java:2228) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125) at org.hibernate.loader.Loader.list(Loader.java:2120) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:835) at eplayers.modele.MangerAnnonceModele.getAnnonceCount(MangerAnnonceModele.java:119) at eplayers.ManagerAnnonceAction.etudeChoixAnnoncejeuClassiqueORAll(ManagerAnnonceAction.java:270) at eplayers.ManagerAnnonceAction.laissePasser(ManagerAnnonceAction.java:119) at sun.reflect.GeneratedMethodAccessor117.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) ** END NESTED EXCEPTION ** Last packet sent to the server was 1 ms ago. at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2757) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2650) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1581) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695) at com.mysql.jdbc.Connection.execSQL(Connection.java:3026) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1137) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1231) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) at org.hibernate.loader.Loader.getResultSet(Loader.java:1808) at org.hibernate.loader.Loader.doQuery(Loader.java:697) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) at org.hibernate.loader.Loader.doList(Loader.java:2228) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125) at org.hibernate.loader.Loader.list(Loader.java:2120) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:835) at eplayers.modele.MangerAnnonceModele.getAnnonceCount(MangerAnnonceModele.java:119) at eplayers.ManagerAnnonceAction.etudeChoixAnnoncejeuClassiqueORAll(ManagerAnnonceAction.java:270) at eplayers.ManagerAnnonceAction.laissePasser(ManagerAnnonceAction.java:119) at sun.reflect.GeneratedMethodAccessor117.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) ** END NESTED EXCEPTION **

    FreeMarker template error!

    Method public java.lang.String org.hibernate.exception.NestableRuntimeException.getMessage(int) threw an exception when invoked on org.hibernate.exception.JDBCConnectionException: could not execute query The problematic instruction: ———- ==> ${msg[0]} [on line 68, column 29 in org/apache/struts2/dispatcher/error.ftl] ———- Java backtrace for programmers: ———- freemarker.template.TemplateModelException: Method public java.lang.String org.hibernate.exception.NestableRuntimeException.getMessage(int) threw an exception when invoked on org.hibernate.exception.JDBCConnectionException: could not execute query at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130) at freemarker.ext.beans.SimpleMethodModel.get(SimpleMethodModel.java:138) at freemarker.core.DynamicKeyName.dealWithNumericalKey(DynamicKeyName.java:111) at freemarker.core.DynamicKeyName._getAsTemplateModel(DynamicKeyName.java:90) at freemarker.core.Expression.getAsTemplateModel(Expression.java:89) at freemarker.core.Expression.getStringValue(Expression.java:93) at freemarker.core.DollarVariable.accept(DollarVariable.java:76) at freemarker.core.Environment.visit(Environment.java:221) at freemarker.core.MixedContent.accept(MixedContent.java:92) at freemarker.core.Environment.visit(Environment.java:221) at freemarker.core.IfBlock.accept(IfBlock.java:82) at freemarker.core.Environment.visit(Environment.java:221) at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179) at freemarker.core.Environment.visit(Environment.java:428) at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102) at freemarker.core.Environment.visit(Environment.java:221) at freemarker.core.MixedContent.accept(MixedContent.java:92) at freemarker.core.Environment.visit(Environment.java:221) at freemarker.core.IfBlock.accept(IfBlock.java:82) at freemarker.core.Environment.visit(Environment.java:221) at freemarker.core.MixedContent.accept(MixedContent.java:92) at freemarker.core.Environment.visit(Environment.java:221) at freemarker.core.Environment.process(Environment.java:199) at freemarker.template.Template.process(Template.java:259) at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:830) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:534) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.NullPointerException at freemarker.ext.beans.SimpleMemberModel.unwrapArguments(SimpleMemberModel.java:86) at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106) … 49 more

  • crp

    Hi MKYong ,

    I am using Struts 2 – Hibernate3.0 in my application. I am facing following exception after few immediate database calls . Exception is as follow ,can you give me any suggestion :

    java.lang.NullPointerException
    WARNING: StandardWrapperValve[default]: PWC1406: Servlet.service() for servlet default threw exception
    java.lang.IllegalStateException
    at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:488)
    at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:725)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
    at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:619)

    WARNING: Response Error during finishResponse
    java.lang.NullPointerException
    at com.sun.enterprise.v3.services.impl.monitor.MonitorableSelectionKeyHandler$CloseHandler.notifyClosed(MonitorableSelectionKeyHandler.java:94)
    at com.sun.enterprise.v3.services.impl.monitor.MonitorableSelectionKeyHandler$CloseHandler.remotlyClosed(MonitorableSelectionKeyHandler.java:90)
    at com.sun.grizzly.BaseSelectionKeyHandler.notifyRemotlyClose(BaseSelectionKeyHandler.java:233)
    at com.sun.grizzly.util.OutputWriter.notifyRemotelyClosed(OutputWriter.java:353)
    at com.sun.grizzly.util.OutputWriter.flushChannel(OutputWriter.java:148)
    at com.sun.grizzly.util.OutputWriter.flushChannel(OutputWriter.java:76)
    at com.sun.grizzly.http.SocketChannelOutputBuffer.flushChannel(SocketChannelOutputBuffer.java:326)
    at com.sun.grizzly.http.SocketChannelOutputBuffer.flushBuffer(SocketChannelOutputBuffer.java:398)
    at com.sun.grizzly.http.SocketChannelOutputBuffer.endRequest(SocketChannelOutputBuffer.java:389)
    at com.sun.grizzly.http.ProcessorTask.action(ProcessorTask.java:1090)
    at com.sun.grizzly.tcp.Response.action(Response.java:268)
    at com.sun.grizzly.tcp.Response.finish(Response.java:412)
    at org.apache.catalina.connector.OutputBuffer.close(OutputBuffer.java:341)
    at org.apache.catalina.connector.Response.finishResponse(Response.java:582)
    at org.apache.catalina.connector.CoyoteAdapter.afterService(CoyoteAdapter.java:370)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.afterService(ContainerMapper.java:366)
    at com.sun.grizzly.http.ProcessorTask.finishResponse(ProcessorTask.java:760)
    at com.sun.grizzly.http.ProcessorTask.postResponse(ProcessorTask.java:750)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:726)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:619)

  • Orozco Hsu

    Please help me, more detail is better, thanks in advance !
    I’ve tried many times but I still don’t know how to resolve this error wihen doing marven

    the error is:

    SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

    I googled many sites, even I reference your another post “manually install jar to marven”, but it still shows up “Failed to load class …..”

    • http://www.mkyong.com mkyong

      Post your last error caused by.

  • kirokw san

    What should I do to run it on glasfish or tomcat? Thanks in advance!

  • tom

    How would I go about setting up struts2 xml form validation on the input boxes in this example?

  • Shaswat

    Hi,
    When will listCustomer() method in CustomerAction will be called ????

  • Anshul

    hi mkyong,

    I did it bymyself :)

    Thanks

  • Anshul

    hi mkyong,

    i am getting

    Struts has detected an unhandled exception:
    Messages:
    File: com/mkyong/customer/action/CustomerAction.java
    Line number: 71
    Stacktraces
    java.lang.NullPointerException

    line no 71 is SessionFactory sessionFactory =
    (SessionFactory) ServletActionContext.getServletContext()
    .getAttribute(HibernateListener.KEY_NAME);

    It throws null and says

    Note: An exception occurred while getting the Javadoc. See log for details.

    i can see in the .classpath the values as

    which is not there in my system as its an ubuntu system.

    Please tell me the remedy for this

    Thnaks
    Regards
    Anshul

  • Anshul

    hi,

    I tried to run the example but got the following error:

    Struts Problem Report

    Struts has detected an unhandled exception:
    Messages:
    File: com/mkyong/customer/action/CustomerAction.java
    Line number: 71
    Stacktraces
    java.lang.NullPointerException

    com.mkyong.customer.action.CustomerAction.listCustomer(CustomerAction.java:71)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    java.lang.Thread.run(Thread.java:662)

    You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:

    struts.devMode=false

    in your WEB-INF/classes/struts.properties file.

    Any help would really be appreciated.

    Thanks
    Regards
    Anshul

    • Janith

      I had same issue.By changing Hibernate version it worked.
      I change pom.xml

      org.hibernate
      hibernate-entitymanager
      4.1.9.Final

  • tom

    Mkyong Can you help?
    If I launch the page directly from

    http://localhost:8080/Struts2Example/pages/customer.jsp

    I see the following error in the logs:

    WARNING: Caught an exception while evaluating expression ‘customerList.size() > 0′ against value stack
    java.lang.NullPointerException: target is null for method size

    Upon trying to submit data I receive the following Hibernate error

    org.hibernate.PropertyValueException: not-null property references a null or transient value: com.paul.customer.model.Customer.createdDate

    But if i access the project as the example suggests
    http://localhost:8080/Struts2Example/listCustomerAction.action

    I see the following struts error report about the Hibernate sql submitted

    Struts Problem Report

    Struts has detected an unhandled exception:

    Messages:
    Unknown column ‘customer0_.customerId’ in ‘field list’
    FreeMarker template error!

    Method public java.lang.String org.hibernate.exception.NestableRuntimeException.getMessage(int) threw an exception when invoked on org.hibernate.exception.SQLGrammarException: could not execute query
    The problematic instruction:
    ———-
    ==> ${msg[0]} [on line 68, column 29 in org/apache/struts2/dispatcher/error.ftl]
    ———-

    Java backtrace for programmers:
    ———-
    freemarker.template.TemplateModelException: Method public java.lang.String org.hibernate.exception.NestableRuntimeException.getMessage(int) threw an exception when invoked on org.hibernate.exception.SQLGrammarException: could not execute query

  • tom

    The instructions don’t go into any depth on how to create the required ServletContextListener and the referenced link doesnt work

    http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html

    Can you please out line the steps required in this process – sorry if its so simple it doesnt even need to be explained.

  • tom

    I renamed the classes now I receive this error, but I can’t find where its referenced?

    SEVERE: Error configuring application listener of class com.tom.listener.HibernateListener
    java.lang.NoClassDefFoundError: com/tom/listener/HibernateListener (wrong name: com/mkyong/listener/HibernateListener)

  • Krish

    HI i got this error, I just download this Struts 2 + Hibernate integration example and i placed all dependencies. but i got this error , give me suggestions please to fix this issue

    SEVERE: Error configuring application listener of class com.mkyong.listener.HibernateListener
    java.lang.NoClassDefFoundError: Lorg/hibernate/cfg/Configuration;
    	at java.lang.Class.getDeclaredFields0(Native Method)
    	at java.lang.Class.privateGetDeclaredFields(Unknown Source)
    	at java.lang.Class.getDeclaredFields(Unknown Source)
    	at org.apache.catalina.core.DefaultInstanceManager.populateAnnotationsCache(DefaultInstanceManager.java:276)
    	at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:143)
    	at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:125)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701)
    	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5260)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1525)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1515)
    	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    	at java.util.concurrent.FutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
    	... 16 more
    Mar 13, 2012 3:49:19 PM org.apache.catalina.core.StandardContext listenerStart
    SEVERE: Skipped installing application listeners due to previous error(s)
    Mar 13, 2012 3:49:19 PM org.apache.catalina.core.StandardContext startInternal
    SEVERE: Error listenerStart
    Mar 13, 2012 3:49:19 PM org.apache.catalina.core.StandardContext startInternal
    SEVERE: Context [/Struts2Example] startup failed due to previous errors
    Mar 13, 2012 3:49:19 PM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler [&quot;http-bio-8080&quot;]
    Mar 13, 2012 3:49:19 PM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler [&quot;ajp-bio-8009&quot;]
    Mar 13, 2012 3:49:19 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 255 ms
    • PhongNQ

      I got the same errors. May I help you to fix this..
      I think it problems in .classpath and tomcat lib but don’t know how to fix it.

  • tom

    I’m getting the following error from eclipse
    The type javax.servlet.ServletContext cannot be resolved. It is indirectly referenced from required .class files

    Does the servlet-api-2.5.jar need to be referenced in the library?

    • Ryan

      any answers on this. im also getting the same eclipse error

  • tom

    Why is eclipse in linux show me this?
    Project ‘Struts2Example’ is missing required library: ‘C:/Program Files/Java/jdk1.6.0_13/lib/tools.jar’

  • tom

    eclipse is giving me this strange missing library requirement.. not surprising as im in linux.

    Project ‘Struts2Example’ is missing required library: ‘C:/Program Files/Java/jdk1.6.0_13/lib/tools.jar’

  • Narasappa

    hi I am Narasappa from bangalore.Currently I am working on Struts 2.0.I need help in displaying image Stored in mysql Using Struts 2.0.please do the the neewd full

  • Ali Syed

    Hi,

    Thanks for the tutorial, I believe we need to make the below changes to pom.xml for the example to work on Tomcat 7 and MySQl5.5

    Option 1 – Replace cglib 2.2 with cglib-nodep 2.2.2 (contains asm dependencies)

    &lt;dependency&gt;
        &lt;groupId&gt;cglib&lt;/groupId&gt;
        &lt;artifactId&gt;cglib-nodep&lt;/artifactId&gt;
        &lt;version&gt;2.2.2&lt;/version&gt;
    &lt;/dependency&gt;

    Option 2 – Keep cglib 2.2 and add asm dependency

    &lt;dependency&gt;
    	&lt;groupId&gt;cglib&lt;/groupId&gt;
    	&lt;artifactId&gt;cglib&lt;/artifactId&gt;
    	&lt;version&gt;2.2&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
    	&lt;groupId&gt;asm&lt;/groupId&gt;
    	&lt;artifactId&gt;asm&lt;/artifactId&gt;
    	&lt;version&gt;3.1&lt;/version&gt;
    &lt;/dependency&gt;
    • Guillermo

      Thxs!!!!!

    • http://adritah.es Ramon

      Thanks, that was the issue with the NullPointerException!

  • santosh limbu

    i am in love with all your work…..amazing work …

  • Java Guru

    Thanks a lot Kong, that post is very good and helpful for me.

  • Xin

    Dear Mkyong,

    I got the following error, would you please give a hint?

    java.lang.NoClassDefFoundError: javax/transaction/Synchronization
    org.hibernate.impl.SessionImpl.(SessionImpl.java:214)
    org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:520)
    org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:544)
    org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:552)
    com.mkyong.customer.action.CustomerAction.addUser(CustomerAction.java:46)

    Thanks in advance,

    Xin

    • Xin

      One info from mkyong’s site is “This is caused by missing of the “jta.jar“, usually happened in Hibernate transaction development.” But I do have jta-1.0.1B.jar in path.

      Xin

      • Xin

        Hi Mkyong,

        Thank you for reply. It didn’t work even jta-1.0.1B.jar (manually downloaded) was added to path. It finally worked when it was moved to .m2 folder.

        Also, it seems that the jar for ServletActionContext is missing. javax.servlet-5.1.12 was downloaded and added to path. is it right version?

        I’m also wondering that if you have any comment about this post, here is the url:
        http://stackoverflow.com/questions/5687886/storing-hibernate-sessionfactory-with-struts

        “I notice the example doesn’t seem to ever close the SessionFactory so I added some code in the contextDestroyed. Was this necessary?”

        Thanks for help,

        Xin

    • http://www.mkyong.com mkyong

      Is this your last caused by error message? Make sure either jta.jar or javaee.jar is included.

  • Xin

    Hi,

    It is very nice tutorial. I got one issue, I would very appreciate that if you could take a look the following message?

    >mvn -X compile


    [ERROR] Failed to execute goal on project Struts2Example: Could not resolve dependencies for project com.mkyong.common:Struts2Example:war:com.mkyong.common: Failure to find javax.transaction:jta:jar:1.0.1B in http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project Struts2Example: Could not resolve dependencies for project com.mkyong.common:Struts2Example:war:com.mkyong.common: Failure to find javax.transaction:jta:jar:1.0.1B in http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced………….

    Thank you very much,

    Xin

    • Xin

      It couldn’t find jdbc driver. It is ok to me. I am actually using mysql.

      Thanks a lot,

      Xin

      • LuZcila

        I have the same problem.
        How do you fixed it?

        Thanks!

  • christopher

    I have resolved the 404 error.Now am getting error 500

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    java.lang.NullPointerException
    	com.mkyong.customer.action.CustomerAction.addCustomer(CustomerAction.java:46)
    	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	java.lang.reflect.Method.invoke(Unknown Source)

    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.30 logs.

    Kindly help me out.Thanks in Advance

    • http://www.mkyong.com mkyong

      NullPointer, what’s your last caused by , see CustomerAction.java: line 46

  • christopher

    am getting 404 error.Can any one help me out.Thanks in Advance

  • subash

    i have imported the downloaded project in Eclipse IDE.
    but where i have to place the lib files i am getting confused. will u suggest me

    • http://www.mkyong.com mkyong

      This is Maven based project, use Maven to get all the dependency library

  • Justin

    Thanks for the tutorial.

    You create the SessionFactory in the contextInitialized() method of the HibernateListener class. Would it be a good idea to add factory.close() in the contextDestroyed() method? or is this not necessary? Thanks!

    • http://www.mkyong.com mkyong

      Logically, it should, but NOT practical. Normally, we shut down our application by issuing kill command, unless you have a UI access, and many times, UI can’t stop your application :)

      But both ways are NO guarantee to run contextDestroyed(), so do not puts any of dependency logic here.

  • http://n/a padmanabha

    I get following exception when i deploy this example

    ------------------------------------------------------------------------
    SessionFactory sessionFactory = 
                 (SessionFactory) ServletActionContext.getServletContext()
                         .getAttribute(HibernateListener.KEY_NAME);
     
    ln no.51        Session session = sessionFactory.openSession();
    ------------------------------------------------------------------------
     
    java.lang.NullPointerException
     
    com.mkyong.customer.action.CustomerAction.addCustomer(CustomerAction.java:51)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    • http://www.mkyong.com mkyong

      Did you configured the “HibernateListener” in web.xml?

      • http://n/a padmanabha

        thanks for the reply .. In my web.xml I have

        com.mkyong.listener.HibernateListener

        • Harneet

          Is this problem resolved?

          If yes, what is the solution?

          • http://[email protected] neosky11

            I get the same problem and my web.xml has the hibernate listener?
            I also added one more line to the Hibernate.cfg.xml

            &lt;property name=&quot;hibernate.connection.driver_class&quot;&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      • payal

        Hello mkyong,

        Your tutorials are great and very helpful for newbies like us.
        I am also getting the Null Pointer Exception on the same line

        Session session = sessionFactory.openSession();

        java.lang.NullPointerException
        at weblogic.servlet.internal.ServletResponseImpl.sendContentError(ServletResponseImpl.java:643)
        at weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:687)
        at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:876)
        at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:567)
        at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)

        The Listener is already configured in the web.xml.Is there anything else that needs to be done to fix this.Any guidance on how to resolve this would be greatly appreciated.

        Thanks
        Payal

    • Muthu

      This pom is missing with the dependency

      javax.servlet
      servlet-api
      2.5
      provided

      • Muthu

        This pom is missing with the dependency

        javax.servlet
        servlet-api
        2.5
        provided

  • http://www.digitalprizm.com jerson

    Hi,
    I have a dynamic query generating from hibernate and the Result List object cannot be mapped with any of my model calss and now I want to display this list in my jsp page using iterator …How can approach for this..Pls suggest me something

    Many Thanks and Regards,
    Jerson

  • http://www.javahowto.net/ Oscar Calderon

    Thanks a lot Kong, that post is very useful to me. I work with struts2 but i commit the mistake of initialize an hibernate session factory for each java session (each application user that login) but your approach is more improved.

    I just have 2 questions (Sorry if my english is strange, i’m from central america):

    1. Suppose that i apply your approach in my project and Hibernate session factory is initialized after application is deployed and it works fine, but in some moment, the database is down and connection in the application is lost. Then a user tries to login but because the database was down for a moment, Hibernate session factory loses the connection with the database. What would be the best approach to recover connection again? Initialize again the Hibernate session factory and put on servlet context (application scope)?

    2. I read a little bit about hibernate’s pooling connection libraries like c3p0 (because default hibernate connection pooling isn’t recommended for production use) and i read that one of the main purposes about using connection pool mechanisms for an application is to mantain connections open, just-to-grab when you need it. If i use c3p0 in my application, it means that i don’t need or have to close the hibernate session after i use it?

  • Ratneswar

    Hello Yong,

    I have a configuration issue with weblogic, I am able to see the results in tomcat 6.0.29 without any issues.

    Issue: struts 2, hibernate, weblogic 9.2 configuration issue

    Getting data from the database, however, action class not forwarding results to jsp page.

    In the weblogic logs, action method is continuously running in infinite loop, not sure why behaving it. Here is list method code.

    public String list()
    {
    System.out.println(“entered in to UserAction list() “);
    SessionFactory sessionFactory = (SessionFactory) ServletActionContext.getServletContext().getAttribute(HibernateListener.KEY_NAME);
    Session session = sessionFactory.openSession();
    userList = userDAO.listUser();
    System.out.println(“end UserAction list() ……………”+userList.size());
    for (int i = 0; i < userList.size(); i++) {
    System.out.println(userList.get(i).getFirstName());
    }
    HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);

    // below Dispatcher NOT WORKING EAITHER
    request.getRequestDispatcher("/DateTest.jsp");
    System.out.println("after forward ……………");
    return SUCCESS;
    }

    Here is weblogic log:
    entered in to UserAction list()
    Hibernate: select users0_.USER_ID as USER1_5_, us
    as USER4_5_, users0_.USER_COUNTRY as USER5_5_, u
    ST as USER8_5_ from USERS users0_
    end UserAction list() ……………6
    Ratneswar
    Test
    Testttttt
    Test12
    Rod
    Ratneswar
    after forward ……………
    entered in to UserAction list()
    Hibernate: select users0_.USER_ID as USER1_5_, us
    as USER4_5_, users0_.USER_COUNTRY as USER5_5_, u
    ST as USER8_5_ from USERS users0_
    end UserAction list() ……………6
    Ratneswar
    Test
    Testttttt
    Test12
    Rod
    Ratneswar
    after forward ……………
    entered in to UserAction list()
    Hibernate: select users0_.USER_ID as USER1_5_, us
    as USER4_5_, users0_.USER_COUNTRY as USER5_5_, u
    ST as USER8_5_ from USERS users0_
    end UserAction list() ……………6
    Ratneswar
    Test
    Testttttt
    Test12
    Rod
    Ratneswar
    after forward ……………
    entered in to UserAction list()

    Would you please advice me what I am doing wrong?

    here is struts.xml action class

    /register.jsp

    greatly appriciated your help.

    Thanks
    Ratneswar

    • http://www.mkyong.com mkyong

      Since it worked in Tomcat, it may be caused by weblogic didnt support certain function.

      Suggestions :

      1. Try ServletRequestAware see if you’re lucky :)
      http://www.mkyong.com/struts2/how-to-get-the-httpservletrequest-in-struts-2/

      2. Assume you are using Eclipse, add a weblogic plugin and debug in IDE.

      Sorry, not familiar with weblogic, hope help.

      • Ratneswar

        Thanks for your reply, working fine now, these are the changes I made

        changed Struts related jar files

        from: struts2-core-2.0.11.jar, xwork-2.0.4.jar,
        struts2-fullhibernatecore-plugin-2.2.1-GA.jar

        to: struts2-core-2.1.6.jar, xwork-2.1.2.jar,
        struts2-fullhibernatecore-plugin-1.4-GA.jar

        add weblogic.xml file along with the struts.xml

        Thanks again,
        Ratneswar

  • Abhishek

    I have two tables in my database.one being “user” where the user email is stored,and the other being “work exp” where the user’s work experience is stored.I am mapping the two tables with an “id”.can you please suggest me the code by which i can map the user id to it’s work experience.
    I am using Struts 2 with hibernate and spring.

    Thanks in Advance
    Abhishek

  • tikaa

    heii
    why i can’t insert into database

    public String insertContacts() throws Exception {
    try {
    session.beginTransaction();
    session.save(getContacts());
    session.getTransaction().commit();
    }
    catch(Exception e) {
    e.printStackTrace();
    session.getTransaction().rollback();
    }
    return SUCCESS;
    }

    • http://www.mkyong.com mkyong

      your code snippet look fine, do you have any error messages logged in your server?

  • Pingback: Struts 2 + Spring + Hibernate integration example()

  • Pingback: Struts 2 + Hibernate integration with “Full Hibernate Plugin”()