Tutorial: Create Struts2 Hibernate Example in Eclipse

      

This is a demo Contact Manager application that we will create using Struts2 and Hibernate framework. In this article we will see how we can use Hibernate to perform Insert / Delete operations in Struts2 framework.

Our Goal

Our goal will be to demonstrate the use of Struts2 with Hibernate framework and to create a demo application “Contact Manager”. The basic requirement of the Contact Manager app will be:

  1. Add new contact in the contact list.
  2. Display all contacts from contact list.
  3. Delete a contact from contact list.

Once we will build the application it will look like:
struts2-hibernate-contact-manager

Getting Started

For our Contact Manager example, we will use MySQL database. Create a table contacts in any MySQL database. This is very preliminary example and thus we have minimum columns to represent a contact. Feel free to extend this example and create a more complex application.

CREATE TABLE CONTACTS
(
	id 		INT PRIMARY KEY AUTO_INCREMENT,
	firstname 	VARCHAR(30),
	lastname	VARCHAR(30),
	cell_no		VARCHAR(15),
	email_id	VARCHAR(30),
	website		VARCHAR(150),
	birthdate	DATE,
	created		TIMESTAMP DEFAULT NOW()
);

Creating Project in Eclipse

Open Eclipse and goto File -> New -> Project and select Dynamic Web Project in the New Project wizard screen.
struts dynamic web project

After selecting Dynamic Web Project, press Next.
dynamic web project

Write the name of the project. For example ContactManager. Once this is done, select the target runtime environment (e.g. Apache Tomcat v6.0). This is to run the project inside Eclipse environment. After this press Finish.

We will need a source folder called resources. Right click on Project in project explorer and select New -> Source Folder and create a folder with name resources.

Also we will create Java packages for our application. As we will use Struts2, we will follow MVC architecture. Create 4 packages in the sources.
struts2-hibernate-package

We created 4 new packages. The net.viralpatel.contact.controller will hold the Java class that will act as controller and will fetch the data from database and pass it to view. The net.viralpatel.contact.model package will hold the Hibernate persistent model class. The net.viralpatel.contact.view will contain the struts2 action class. And finally the net.viralpatel.contact.util will have some hibernate related util file that will be see shortly.

Required JAR Files

Now copy all the required JAR files in WebContent -> WEB-INF -> lib folder. Create this folder if it does not exists.

Create JSP for Contact Manager

We will need only one JSP file for this tutorial. The JSP will include a form to add new contact as well as will list the contacts at the end. Create a JSP file index.jsp in WebContent folder and copy following content into it.
WebContent/index.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
	<title>Contact Manager - Struts2 Hibernate Example</title>
</head>
<body>

<h1>Contact Manager</h1>
<s:actionerror/>

<s:form action="add" method="post">
	<s:textfield name="contact.firstName" label="Firstname"/>
	<s:textfield name="contact.lastName" label="Lastname"/>
	<s:textfield name="contact.emailId" label="Email"/>
	<s:textfield name="contact.cellNo" label="Cell No."/>
	<s:textfield name="contact.website" label="Homepage"/>
	<s:textfield name="contact.birthDate" label="Birthdate"/>
	<s:submit value="Add Contact" align="center"/>
</s:form>

<h2>Contacts</h2>
<table>
<tr>
	<th>Name</th>
	<th>Email</th>
	<th>Cell No.</th>
	<th>Birthdate</th>
	<th>Homepage</th>
	<th>Delete</th>
</tr>
<s:iterator value="contactList" var="contact">
	<tr>
		<td><s:property value="lastName"/>, <s:property value="firstName"/> </td>
		<td><s:property value="emailId"/></td>
		<td><s:property value="cellNo"/></td>
		<td><s:property value="birthDate"/></td>
		<td><a href="<s:property value="website"/>">link</a></td>
		<td><a href="delete?id=<s:property value="id"/>">delete</a></td>
	</tr>
</s:iterator>
</table>
</body>
</html>

Adding Hibernate Support

For adding hibernate support, we will add following source code in Contact Manager application.
hibernate.cfg.xml – This is the Hibernate configuration file. This file will contain configurations such as database connection information, persistence class info etc. Create hibernate.cfg.xml under resources folder and copy following content into it.

<?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="connection.driver_class">
			com.mysql.jdbc.Driver
		</property>
		<property name="connection.url">
			jdbc:mysql://localhost:3306/ContactManager
		</property>
		<property name="connection.username">root</property>
		<property name="connection.password">root</property>
		<property name="connection.pool_size">1</property>
		<property name="dialect">
			org.hibernate.dialect.MySQLDialect
		</property>
		<property name="current_session_context_class">thread</property>
		<property name="cache.provider_class">
			org.hibernate.cache.NoCacheProvider
		</property>
		<property name="show_sql">true</property>
		<property name="hbm2ddl.auto">update</property>

		<mapping class="net.viralpatel.contact.model.Contact" />

	</session-factory>
</hibernate-configuration>

HibernateUtil.java – This is the Util file that we use to create connection with hibernate. Create HibernateUtil.java under package net.viralpatel.contact.util and copy following content into it.

package net.viralpatel.contact.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {

	private static final SessionFactory sessionFactory = buildSessionFactory();

	private static SessionFactory buildSessionFactory() {
		try {
			// Create the SessionFactory from hibernate.cfg.xml
			return new AnnotationConfiguration().configure()
					.buildSessionFactory();
		} catch (Throwable ex) {
			System.err.println("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
}

Contact.java – This is the persistence entity class that will map to Contacts table in MySQL. Create Contact.java under net.viralpatel.contact.model package and copy following content into it.

package net.viralpatel.contact.model;

import java.io.Serializable;
import java.sql.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="Contacts")
public class Contact implements Serializable{

	private static final long serialVersionUID = -8767337896773261247L;

	private Long id;
	private String firstName;
	private String lastName;
	private String emailId;
	private String cellNo;
	private Date birthDate;
	private String website;

	private Date created;

	@Id
	@GeneratedValue
	@Column(name="id")
	public Long getId() {
		return id;
	}
	@Column(name="firstname")
	public String getFirstName() {
		return firstName;
	}
	@Column(name="lastname")
	public String getLastName() {
		return lastName;
	}
	@Column(name="email_id")
	public String getEmailId() {
		return emailId;
	}
	@Column(name="cell_no")
	public String getCellNo() {
		return cellNo;
	}
	@Column(name="birthdate")
	public Date getBirthDate() {
		return birthDate;
	}
	@Column(name="website")
	public String getWebsite() {
		return website;
	}
	@Column(name="created")
	public Date getCreated() {
		return created;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public void setEmailId(String emailId) {
		this.emailId = emailId;
	}
	public void setCellNo(String cellNo) {
		this.cellNo = cellNo;
	}
	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}
	public void setCreated(Date created) {
		this.created = created;
	}
	public void setWebsite(String website) {
		this.website = website;
	}
}

Note how we have mapped Contact class with Contacts table using Java persistence API annotations.

Adding Controller to access data

We will add a controller class in Contact Manager application which will be used to get/save data from hibernate. This controller will be invoked from Struts action class. Create a file ContactManager.java under net.viralpatel.contact.controller package and copy following content into it.

package net.viralpatel.contact.controller;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import net.viralpatel.contact.model.Contact;
import net.viralpatel.contact.util.HibernateUtil;

public class ContactManager extends HibernateUtil {

	public Contact add(Contact contact) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.save(contact);
		session.getTransaction().commit();
		return contact;
	}
	public Contact delete(Long id) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Contact contact = (Contact) session.load(Contact.class, id);
		if(null != contact) {
			session.delete(contact);
		}
		session.getTransaction().commit();
		return contact;
	}

	public List<Contact> list() {

		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<Contact> contacts = null;
		try {

			contacts = (List<Contact>)session.createQuery("from Contact").list();

		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return contacts;
	}
}

Note that how we have created different methods in controller class to add/delete/list the contacts. Also the ContactManager class is extending HibernateUtil class thus allowing it to access sessionFactory object.

Adding Struts2 Support

Let us add Struts2 support to our web application. For that, will add following entry in deployment descriptor (WEB-INF/web.xml).

Add Struts2 Filter in web.xml

<filter>
	<filter-name>struts2</filter-name>
	<filter-class>
		org.apache.struts2.dispatcher.FilterDispatcher
	</filter-class>
</filter>
<filter-mapping>
	<filter-name>struts2</filter-name>
	<url-pattern>/*</url-pattern>
</filter-mapping>

Creating struts.xml

We will need to create struts.xml file that will hold the action mapping for our example. Create a file struts.xml in resources folder and add following content into it.
struts.xml

<?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.enable.DynamicMethodInvocation"
		value="false" />
	<constant name="struts.devMode" value="false" />

	<package name="default" extends="struts-default" namespace="/">

		<action name="add"
			class="net.viralpatel.contact.view.ContactAction" method="add">
			<result name="success" type="chain">index</result>
			<result name="input" type="chain">index</result>
		</action>

		<action name="delete"
			class="net.viralpatel.contact.view.ContactAction" method="delete">
			<result name="success" type="chain">index</result>
		</action>

		<action name="index"
			class="net.viralpatel.contact.view.ContactAction">
			<result name="success">index.jsp</result>
		</action>
	</package>
</struts>

Related:
Create Struts Application in Eclipse
Create Struts2 Application in Eclipse

Create Action class

Up-till now we have almost completed our Contact Manager application in Struts2 and Hibernate. Only task left is to add Struts Action class. Create a class ContactAction.java under net.viralpatel.contact.view package and copy following content into it.

package net.viralpatel.contact.view;

import java.util.List;

import net.viralpatel.contact.controller.ContactManager;
import net.viralpatel.contact.model.Contact;

import com.opensymphony.xwork2.ActionSupport;

public class ContactAction extends ActionSupport {

	private static final long serialVersionUID = 9149826260758390091L;
	private Contact contact;
	private List<Contact> contactList;
	private Long id;

	private ContactManager linkController;

	public ContactAction() {
		linkController = new ContactManager();
	}
	public String execute() {
		if(null != contact) {
			linkController.add(getContact());
		}
		this.contactList = linkController.list();
		System.out.println(contactList);
		System.out.println(contactList.size());
		return SUCCESS;
	}
	public String add() {
		System.out.println(getContact());
		try {
		linkController.add(getContact());
		}catch(Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	public String delete() {
		linkController.delete(getId());
		return SUCCESS;
	}
	public Contact getContact() {
		return contact;
	}
	public List<Contact> getContactList() {
		return contactList;
	}
	public void setContact(Contact contact) {
		this.contact = contact;
	}
	public void setContactList(List<Contact> contactsList) {
		this.contactList = contactsList;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
}

ContactAction class contains different methods that gets called by Struts2. The execute() method is the default method which gets called when we call /index action from browser. It fetches the list of contacts and display it in index.jsp. Similarly, when a new contact is added, add() method is called. If you check the action mapping entry in struts.xml for add() method, the <result> is mapped with /index action and the type is chain. This is because we want to display the list of contact once we add a new one. Hence we have done Action chaining and called /index action after /add action.

The Contact Manager App

That’s it. The app is ready, just compile and run the project in Eclipse Run -> Run As -> Run on Server. Set the URL to:
http://localhost:<port>/<project name>/index

struts2-hibernate-contact-manager
Fill the contact form and hit enter and the new contact will be persisted in database and will be shown in below table. Similarly, click on delete link next to a record. It will delete the record from database.

Let me know your input about this application.
Cheers.

Download Source

Download Source without JAR files (19.2 KB)


Facebook  Twitter      Stumbleupon  Delicious
  

52 Comments on “Tutorial: Create Struts2 Hibernate Example in Eclipse”

  • Antti wrote on 19 January, 2010, 21:25

    First of all, thanks for the struts2 tutorials.

    All the other examples worked well but in this one I seem to get two identical inserts every time I post the form. What might cause this? I’ll try to dig into it this evening, but just in case I can’t figure it out…

  • GelbeTT wrote on 22 January, 2010, 13:36

    I have the same problem with two identical inserts.

  • Viral Patel wrote on 22 January, 2010, 14:02

    @Antti, @GelbeTT: Have you tried to download the source code at the end of article. I think there is some prob with configuration.

  • Rajasekhar wrote on 31 January, 2010, 9:41

    hi viral patel,
    Thanks for your tutorials. and i have one question. can you please tell me how can you load the hibernate.cfg.xml file in the HibernateUtil.java. we have to give the path to that file or it gets automatically. thanks for your help.

  • Viral Patel wrote on 1 February, 2010, 15:54

    Hi Rajasekhar,
    The hibernate.cfg.xml file will be automatically loaded by Hibernate. It must be present in classpath. This is why we have added this file in /resources folder which is a source folder.
    Once the project is compiled, the hibernate.cfg.xml file will be available in WEB-INF/classes folder of webapp.

  • Rajasekhar wrote on 4 February, 2010, 0:14

    thankyou viral.

  • dani wrote on 17 February, 2010, 22:21

    Hello Viral,
    nice job, I enjoy your tutorials. Pretty straight forward. Thank you and keep on like this.

    I have some inputs that can save hours to some like me:

    1° The database created in MySQL must have the same name as specified in hibernate.cfg.xml at line 12(in your example ContactManager). Initially I put the table in other database (you said “in any database”) and obviously the program didn’t find it.

    2° Concerning the double “add” to database, it’s because theres a first “add”: —linkController.add(getContact());— in ContactAction.java line 35, the add() method
    and there’s another one at line 24, in the execute() method.
    I just commented the second one and is working just fine.

    3° At the first access of the page, the table was not populated with data, even if in the DB it exist. I saw you tried to force the execution of “index.action” (which is in fact the execute() method of ContactAction class) by not declaring any parameter in web.xml
    For some reason it doesn’t work and I wonder if is fault of my configuration?
    For me, the solution was to:
    a) rename the index.jsp –> display.jsp
    b)in struts.xml redirect the action “index” towards this new page
    c)create a new index.html pretty empty with in the header
    d) eventually indicate in web.xml the index.html

    ok, hoping that this will help somenone

  • dani wrote on 17 February, 2010, 22:28

    well, my previous comment didn’t save the HTML tag so there are 2 lines that should look like this:

    c)create a new index.html pretty empty with (META HTTP-EQUIV=”Refresh” CONTENT=”0;URL=index.action” ) in the header

    and

    d)eventually indicate in web.xml the (welcome-file) index.html (/welcome-file)
    obviously all with brackets instead of parenthesis;

  • Viral Patel wrote on 18 February, 2010, 13:57

    @dani: Thanks for the suggestions. I appreciate your effort to share your inputs. This will be definitely helpful for others. I will also try to modify the post and include your suggestions.

    Thanks again.

  • Mike wrote on 20 February, 2010, 1:06

    I tried the tutorial twice, did everything as you said, but I got: status 404 The requested resource (/Borra/) is not available. If you have any sugestions I would apreciate them. Tnks.

  • mike wrote on 20 February, 2010, 1:08

    I got 404 The requested resource (/Borra/) is not available.
    what can I do?
    tnks

  • digant wrote on 20 February, 2010, 1:38

    Hi Viral, Thanks for the KISS ( keep it short & sweet ) tutorial.
    1. do i have to download each jar files separately or is there any RAR file that contains all the required jar files ? Is there any specific RAR file available by the apache org to make the struts2 appl compatible with Hibernate ?

  • utsav wrote on 24 February, 2010, 10:59

    thanks dear…….
    thank u so so so much………………………

  • mohiz wrote on 24 February, 2010, 11:01

    hi thanks for this demo i appreciate you…………….very much keep giving us more complex example of struts and hibernate with eclipse…..

  • hasna wrote on 25 February, 2010, 13:16

    hi. i am also getting error message404 The requested resource (/helloworld/) is not available.
    @ viral please help

  • hasna wrote on 26 February, 2010, 12:05

    please respond viral

  • Viral Patel wrote on 26 February, 2010, 12:18

    @harna: Check the logs when you starting Tomcat server. There must be error in the log which is causing the issue. Also see if /helloworld/ is the correct name of project. Best way is to start Tomcat inside eclipse only to avoid such issues in development.

  • hasna wrote on 26 February, 2010, 14:58

    Thanks a lot viral…i could solve that problem.but there is one hibernate annotation problem now.
    Initial SessionFactory creation failed.java.lang.NoSuchFieldError: tableNameBinding

  • Viral Patel wrote on 26 February, 2010, 15:25

    @hasna: There must be version conflict in the jar files. Check the jars you have included in your project.

  • suman wrote on 4 March, 2010, 13:56

    Hi Viral,

    Thanks for the Very Use full application. I am new to Hibernate. Could you please explain the flow of the application.

    Thanks
    Suman

  • Zulqarnain Hafeez wrote on 4 March, 2010, 15:41

    I am unable to run the this example can you please tell which Jars required other than these. Because i am getting following errors.
    java.lang.IllegalAccessError at net.sf.cglib.core.ClassEmitter.setTarget(ClassEmitter.java:47)

  • Rajkumar wrote on 8 March, 2010, 11:13

    Hi Viral Patel,
    I got a problem with ur project. When i click the Add Contacts, it show an error states that

    The requested resource (/HibeStr/add) is not available.

    But i do checked struts.xml and everything. I d/led the source file you’ve given. Please let me know whats the problem. I added all needed jar files.

  • Pradeep Kumar wrote on 11 March, 2010, 19:25

    Hi Viral,

    This tutorial is an ladder and makes struts look easy for beginner, you have done nice work by providing the abstract details of each step.

  • Rajkumar wrote on 12 March, 2010, 9:40

    But where is the Contact.hbm.xml file. You haven’t give it.

  • viji wrote on 12 March, 2010, 10:48

    Mr. Vital I have following error when click the add contact buttob
    org.hibernate.HibernateException: No CurrentSessionContext configured!
    org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:572)
    contact.controller.ContactManager.add(ContactManager.java:15)
    contact.view.ContactAction.execute(ContactAction.java:24)
    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)
    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

    and still more.

    please can you help me to get ride of that.
    Thanks in advance
    Viji.

  • zaki ahmad wrote on 22 March, 2010, 12:30

    Thanks buddy. You Tutorial Is really awesome. Thanks Once again.

  • Amit Doshi wrote on 23 March, 2010, 15:08

    Thanks Viral for a very nice tutorials on Struts2, and this one with Struts2 + hibernate and also Danny helped to solve the couple of problems…

    Viral…. Please Continue posting this kind of blog…. It really helps a lot for beginner’s…

    Thank you dear once again..

  • Angelina Peters wrote on 28 March, 2010, 0:15

    Slight change to point 3 mentioned by dani on accesing index.jsp for the first the data is not populted becoz u get the contact list only when u execute methos of action class is executed. since it does not get executed until and unless u click on add button data will not be populated. awork around this u call the add.action class first which will populate the data in the index.jsp.
    secondly in index.jsp the action needs to be changed to add.action and delete.action ,
    and the delete action link should be changed to
    <a href="delete.action?id=”>delete
    also the struts.xml needs to be modified for this example to run smoothly.

    index
    index.jsp

    Rest all is fine

  • Majid wrote on 31 March, 2010, 21:38

    Hi,
    I got this error when tryying to add a contact :

    No result defined for action net.viralpatel.contact.view.ContactAction and result input

    description The requested resource (No result defined for action net.viralpatel.contact.view.ContactAction and result input) is not available.

    Please help
    thanks

  • ronuhr wrote on 5 April, 2010, 14:41

    Hey,
    I also got same error as..
    type Status report

    message No result defined for action net.viralpatel.contact.view.ContactAction and result input

    description The requested resource (No result defined for action
    net.viralpatel.contact.view.ContactAction and result input) is not available.

    Viral, Can you please help me for this error.

    Thanks.

  • Anu wrote on 15 April, 2010, 19:24

    the example is very simple yet illustrative but i m getting the following error.
    java.lang.NoClassDefFoundError: javax/ejb/Column
    i need help

  • deepak wrote on 4 May, 2010, 10:45

    Hey,
    I also got same error as..
    type Status report

    message No result defined for action net.viralpatel.contact.view.ContactAction and result input

    description The requested resource (No result defined for action
    net.viralpatel.contact.view.ContactAction and result input) is not available.

    Viral, Can you please help me for this error.

    Thanks.

  • Anu wrote on 6 May, 2010, 11:01

    @deepak::hey that is a validation error.You are passing value of some other type in the form and receiving it in the class in some other data type..
    Welll i solved my problem.it was due to a jar file conflict.

  • Anu wrote on 6 May, 2010, 11:05

    @deepak:hey that is a validation error.You are submitting value of some type in your form and recieving it in the class in some other form.
    well i solved my problem.It was a jar file conflict problem

  • Kavita wrote on 20 May, 2010, 18:33

    Please send jar file with source code

  • APor wrote on 23 May, 2010, 13:59

    I downloaded hibernate zip file (last version). I cannot find some jars. I know I can look for them just using google, but I though just downloading struts2 and hibernate would have all I need. Can anyone clarify where to download all needed jars? Thanks.

  • amit wrote on 7 June, 2010, 11:54

    hey.. thanks for the step by step example..
    one small thing i thought would be needed is “a confirmation of delete action to be made”.
    a small javascript could make it more smarter. i mean, if u add it here, no one need to look around for this small thing.
    anyways things here are really useful.. keep up the good work
    Cheers

  • vijay wrote on 7 June, 2010, 16:09

    i have a problem to deploy the web application

  • venkat wrote on 9 June, 2010, 9:25

    Hi all,

    i am getting errors as below

    type Status report

    message There is no Action mapped for namespace / and action name add.

    description The requested resource (There is no Action mapped for namespace / and action name add.) is not available.

    ——————————————————————————–

    Apache Tomcat/6.0.18

    olease suggest me what i have to do

  • lupo wrote on 19 June, 2010, 20:14

    Hi, instead of using MySQL, I’m trying the sample with an Oracle DB.
    I managed to retrieve data from the DB, but as I try to insert data I get errors !
    Any advice ? thanks

    java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity
    at org.hibernate.event.SaveOrUpdateEvent.(SaveOrUpdateEvent.java:63)
    at org.hibernate.event.SaveOrUpdateEvent.(SaveOrUpdateEvent.java:46)
    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:550)
    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:546)
    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.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342)
    at $Proxy6.save(Unknown Source)
    at net.lupo.contact.controller.CategorieManager.add(Unknown Source)
    at net.lupo.contact.view.CategorieAction.add(Unknown Source)
    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 com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
    ……
    …….
    ……

  • Elida wrote on 23 June, 2010, 17:16

    Hi, I have a problem that file is not in library so I dont run my project. Please one respond to my problem.

  • Anu wrote on 24 June, 2010, 12:43

    @venkat:make sure u hv defined ‘add’ action in ur struts.xml file

  • Anu wrote on 24 June, 2010, 12:47

    APor:try this-www.findjar.com

  • Elida wrote on 24 June, 2010, 15:21

    Please one help to me. I try to prepare a estate program. I want to add house information delete this and I want to add foto of these house but I cant make this application. My application doesnt run. always make error. and I dont know how I add foto

  • john wrote on 2 July, 2010, 5:28

    use shine enterprise pattern to make some thing like this
    refer to http://www.megaupload.com/?d=ALY55F8F to learn more

  • Manuel wrote on 17 July, 2010, 6:28

    thanks you !!! this application is very good …. !!!
    greetings from Perú

  • Mitesh wrote on 28 July, 2010, 10:23

    hello viral,i follow ur tutorial its nice to learn.i try the same example in my pc for practice which is u given here.but i got some problem which i can’t able to understand.so can u please help me to soleve these proble.i send the error message with these comment ok.so please give me a reply as soon as possible.following is the error:
    ======================================================================
    org.hibernate.MappingException: Unknown entity: src.model.Contact

  • swag01 wrote on 2 August, 2010, 5:36

    Viral;

    Thanks for another great tutorial…

    A note for anyone downloading the latest hibernate….

    The list of jars mentioned in the tutorial are different. It was recommended to just search the net for the jars. Bad news if you blindly replace the jars, especially if you download hibernate 3.5 or greater.

    I’m trying to get this running with hibernate 3.5.3 with postgreSQL and jboss. I’m down to a sequence error; however, it appears jboss included hibernate with the server so I was getting tons of vague conflicts. What I have learned is that a vague error might be a conflict with a jboss supplied jar.

    I finally figured this out by replacing the hibernate libs with what jboss/common/lib was providing and got past many errors. I spent a day+ rewriting the code to find this out. Hey, at least I learned a lot! Now, I need to get jboss to ignore the commons lib and figure out the sequence problem and I will be great.

    Again, thanks Viral, because you have really jumpstarted my understanding of struts2. And now hibernate!

  • ATIF wrote on 12 August, 2010, 11:52

    HI VIRAL I HAVE DONE STEP BY STEP OF THIS APPLICATION. THE APPLICATION GETS COMPILED SUCCESSFULLY BUT AFTER CLICKING THE SUBMIT BUTTON ON THE INDEX PAGE PAGENOT FOUND ERROR COMES HTTP Status 404 – /ContactManager/add
    PLEASE GIVE THE REPLY SO THAT I CAN PROCEED
    THANKS

  • Suresh wrote on 14 August, 2010, 13:02

    why ContactManager is extending HibernateUtil ?

  • manoj wrote on 17 August, 2010, 0:29

    Hi Viral i get an error There is no Action mapped for namespace / and action name add. – [unknown location]

    when i click on submit button. I am usinh oracke 10g as a database.Kindly help me on this

  • tabrez wrote on 25 August, 2010, 11:24

    i m getting following error while running will u please solve this Mr. viral here it goes……………………………

    HTTP Status 404 – There is no Action mapped for namespace / and action name add.

    ——————————————————————————–

    type Status report

    message There is no Action mapped for namespace / and action name add.

    description The requested resource (There is no Action mapped for namespace / and action name add.) is not available.

    ——————————————————————————–

    Apache Tomcat/6.0.24

Write a Comment

Gravatars are small images that can show your personality. You can get your gravatar for free today!

Copyright © 2010 ViralPatel.net. All rights reserved.