aspose file tools*
The moose likes Struts and the fly likes SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown." Watch "SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown." New topic
Author

SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown.

D. Deepak Sharma
Ranch Hand

Joined: May 12, 2012
Posts: 31
Hello Everyone I am writing a Code to use the Hibernate into my Struts Framework so that i created a HibernatePlugIn.java plugin I am using Hibernate 3.6.10 and struts 1.3.10 IDE ecllipse, when I tried to start the Server (TomCat 6.0) so i am getting this error,


Jun 28, 2012 12:14:48 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\PC Connectivity Solution\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Java\jdk1.7.0_01\bin;.
Jun 28, 2012 12:14:49 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StrutsExample1' did not find a matching property.
Jun 28, 2012 12:14:49 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:RegistrationForm' did not find a matching property.
Jun 28, 2012 12:14:51 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jun 28, 2012 12:14:51 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 3856 ms
Jun 28, 2012 12:14:52 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jun 28, 2012 12:14:52 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.35
Jun 28, 2012 12:14:55 PM org.apache.struts.action.ActionServlet initChain
INFO: Loading chain catalog from jar:file:/D:/WorkSpace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/RegistrationForm/WEB-INF/lib/struts-core-1.3.10.jar!/org/apache/struts/chain/chain-config.xml
Jun 28, 2012 12:14:56 PM org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
INFO: Tiles definition factory loaded for module ''.
Setting Path to /hibernate.cfg.xml...
813 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
860 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.10.Final
860 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
875 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
969 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
1828 [main] INFO org.hibernate.cfg.Configuration - configuring from url: file:/D:/WorkSpace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/RegistrationForm/WEB-INF/classes/hibernate.cfg.xml
2000 [main] WARN org.hibernate.util.DTDEntityResolver - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Jun 28, 2012 12:14:59 PM org.apache.struts.action.ActionServlet init
SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown, so marking the servlet as unavailable. Most likely, this is due to an incorrect or missing library dependency.
javax.servlet.ServletException
at org.deepak.connect.HibernatePlugIn.init(HibernatePlugIn.java:50)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:871)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:359)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Jun 28, 2012 12:14:59 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet action as unavailable
Jun 28, 2012 12:14:59 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /RegistrationForm threw load() exception
javax.servlet.UnavailableException
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:402)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Jun 28, 2012 12:15:00 PM org.apache.struts.action.ActionServlet initChain
INFO: Loading chain catalog from jar:file:/D:/WorkSpace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/StrutsExample1/WEB-INF/lib/struts-core-1.3.10.jar!/org/apache/struts/chain/chain-config.xml
Jun 28, 2012 12:15:00 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jun 28, 2012 12:15:01 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jun 28, 2012 12:15:01 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/93 config=null
Jun 28, 2012 12:15:01 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9214 ms

I am pasting the Plugin file i.e. HibernatePlugIn.java

package org.deepak.connect;

import javax.servlet.ServletException;

import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import java.net.URL;


public class HibernatePlugIn implements PlugIn {

private Configuration config;
private SessionFactory factory;
private String path = "/hibernate.cfg.xml";
//private static Class clazz = HibernatePlugIn.class;

public static final String KEY_NAME = SessionFactory.class.getName();
public void setPath(String path){
if(path==null||path.trim().isEmpty()){
throw new IllegalArgumentException("Path Can not be Blank");
}
System.out.println("Setting Path to " + path + "...");
this.path = path;
}
@Override
public void destroy() {
try {
factory.close();
} catch (HibernateException e) {
e.printStackTrace();
}
}

@Override
public void init(ActionServlet servlet, ModuleConfig arg1)
throws ServletException {
try{
//save the Hibernate session factory into serlvet context
URL url = HibernatePlugIn.class.getResource(path);
config = new Configuration().configure(url);
factory = config.buildSessionFactory();
servlet.getServletContext().setAttribute(KEY_NAME, factory);
}
catch (MappingException e) {
throw new ServletException();
} catch (HibernateException e) {
throw new ServletException();
}
}

}

my struts.config.xml is as:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean
name="Reguser"
type="org.deepak.connect.TableForm"/>
</form-beans>

<global-exceptions>
<exception key="reg.deepak.error"
type="java.lang.Exception"
path="/error.jsp"/>
</global-exceptions>
<global-forwards>
<forward name="ioError" path="/error.jsp"></forward>
</global-forwards>
<action-mappings>
<action path="/Reguser" type="org.deepak.connect.TableStrutsAction" name="Reguser"
scope="request" validate="true" input="/UserRegister.jsp">
<forward name = "success" path="/Login/success.jsp"/>
</action>
</action-mappings>
<message-resources parameter= "org.deepak.error.Application"/>
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property value="/WEB-INF/tiles-defs.xml" property="definitions-config"/>
</plug-in>
<plug-in className="org.deepak.connect.HibernatePlugIn">
<set-property value="/hibernate.cfg.xml" property="path"/>
</plug-in>
</struts-config>
So, Please tell me what this error is and how to remove it and yes I have add all the required Hibernate and Struts Jar file in the /WEB-INF/lib folder
Sandy Chatterjee
Ranch Hand

Joined: Jun 27, 2012
Posts: 55

I have seen your previous code.

Why don't you try the below mentioned code.

Try this code:
HibernatePlugin.java

HibernateUtils.java

In struts-config.xml paste this code


Take up one idea. Make that one idea your life; dream of it; think of it; live on that idea. Let the brain, the body, muscles, nerves, every part of your body be full of that idea, and just leave every other idea alone. This is the way to success.
D. Deepak Sharma
Ranch Hand

Joined: May 12, 2012
Posts: 31
Sandy Chatterjee wrote:I have seen your previous code.

Why don't you try the below mentioned code.

Try this code:
HibernatePlugin.java

HibernateUtils.java

In struts-config.xml paste this code



Dear Sir, You have written very nice and clean Code that Solved my problem Thanks for that but I have 2 Questions here while in previous code i was writting the code in single file then why we moved the code from init() function to hibernateutil.java and 2nd why we used ThreadLocal<Session> session and then ultimately again typecast it Hibernate Session means what exactly went wrong with previous code kindly tell me if it does not bother you.

Thanks and Regards Deepak
Sandy Chatterjee
Ranch Hand

Joined: Jun 27, 2012
Posts: 55

Answering your questions

while in previous code i was writting the code in single file then why we moved the code from init() function to hibernateutil.java


You can do it in the init() function as well. For easy understanding I made two different classes.

why we used ThreadLocal<Session> session and then ultimately again typecast it Hibernate Session


For each Action classes a unique thread is generated. So when we are creating a new session instance it has to be Thread safe.
The ThreadLocal class binds the Session object with a particular Thread. i.e The Thread which is used to access the current Session.

what exactly went wrong with previous code kindly tell me if it does not bother you


I don't find anything wrong in your code. It can be due to wrong configuration. Or due to some missing JARs.
Also, make sure that your directory structure is correct.

Can you provide me with a screenshot of the directory structure.
D. Deepak Sharma
Ranch Hand

Joined: May 12, 2012
Posts: 31

I don't find anything wrong in your code. It can be due to wrong configuration. Or due to some missing JARs.
Also, make sure that your directory structure is correct.

Can you provide me with a screenshot of the directory structure.


Sir Screenshots are:


[Download screenshot.bmp] Download

[Download screenshot1.bmp] Download


[Thumbnail for screenshot2.JPG]

Sandy Chatterjee
Ranch Hand

Joined: Jun 27, 2012
Posts: 55

In com.deepak.register package there is an error.
Can you show me where the exact error is.

Please reply back with the following answers:

  • Are you able to run a simple project.
  • Since when are you facing this Issue?
  • Before Connecting to Hibernate was it running fine?
  • Also in HibernatePlugIn.java there is a yellow mark. Open HibernatePlugIn.java and find the message corresponding to that yellow mark.
  • D. Deepak Sharma
    Ranch Hand

    Joined: May 12, 2012
    Posts: 31
    Sandy Chatterjee wrote:In com.deepak.register package there is an error.
    Can you show me where the exact error is.


    Sir Actually That package is one independent package where initially trying to call a Model class Called "Users" but I have not implemented that class yet so That why it is showing class Users can not be resolved.

    Please reply back with the following answers:

  • Are you able to run a simple project.



  • Simple Project is nothing just to learn basic Struts functionality where I have created basic struts examples.

  • Since when are you facing this Issue?


  • Actually after doing practice in struts I wanted to develop a project where I could use the DataBase using Hibernate so for that I tried to develop the code thats how I started learning Hibernate about a month ago and faced this particular error about a week and half, I started with Hibernate version 3.6 so I thought it might be due to its version but That error remained with older versions also.

  • Before Connecting to Hibernate was it running fine?


  • Initially I wrote simple codes for hibernate where i configured connections and used SessionFactory etc and run them as a JAVA APPLICATION everything was smooth but when i attempted to use the power of hibernate with struts this problem arose. I have created many Tables Inserted data using simple codes etc.
  • Also in HibernatePlugIn.java there is a yellow mark. Open HibernatePlugIn.java and find the message corresponding to that yellow mark.

  • First mark is corresponding to
    private SessionFactory factory;
    message is:
    The value of the field HibernatePlugIn.factory is not used

    This is error is showing because in your code you suggested this block as:
    public void destroy() {
    try {
    HibernateUtils.closeSession();
    /*factory.close();*/
    } catch (HibernateException e) {
    e.printStackTrace();
    }
    }
    but There was some error that I can not remember right now but i guessed that i was due to the factory object that was not initialized in our code and we were trying to close that so I called the function from HibernateUtils.java and I worked I have commented it out as you can see.

    second is
    private String path = "/hibernate.cfg.xml";
    message is:
    The value of the field HibernatePlugIn.path is not used
    and third one is:
    private static Class clazz = HibernatePlugIn.class;
    message is
    Class is a raw type. References to generic type Class<T> should be parameterized

    Sir please also guide me How to step further ahead to build my code for handling the database. I give you the scenario where there are multiple form in same application where I want to Use CURD operations on database from these different forms and JSP pages so how to step further ahead.

    Thanks and Regards
    D. Deepak Sharma
    Ranch Hand

    Joined: May 12, 2012
    Posts: 31
    Sir I am continuing with the same program I have written the Action Class which i am using to Collect the data coming from the ActionForm class and I am using the form object and take the value from there and then Inserting the data in the table. When I am doing this whole procedure there is no error but It does not perform the purpose. Action Class Code is ;

    package org.deepak.connect;

    import javax.servlet.http.*;

    import org.apache.commons.beanutils.BeanUtils;
    import org.apache.struts.action.*;
    import org.hibernate.*;



    public class TableStrutsAction extends Action {

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request
    , HttpServletResponse respose)throws Exception{

    SessionFactory factory = (SessionFactory)servlet.getServletContext().getAttribute(HibernatePlugIn.KEY_NAME);
    Session session = factory.openSession();
    session.beginTransaction();

    TableForm tform = new TableForm();
    CreatingTable ctable = new CreatingTable();

    String uid = tform.getUserid();
    String uname = tform.getUsername();

    BeanUtils.copyProperties(ctable, tform);

    ctable.setUserid(uid);
    ctable.setUsername(uname);

    session.save(ctable);
    session.getTransaction().commit();

    return mapping.findForward("success");

    }

    }

    Here CreatingTable is my actual Table I have kept its code simple

    package org.deepak.connect;

    import javax.persistence.Entity;
    import javax.persistence.Id;

    @Entity
    public class CreatingTable {

    private String userid;
    private String username;

    @Id
    public String getUserid() {
    return userid;
    }
    public void setUserid(String userid) {
    this.userid = userid;
    }
    public String getUsername() {
    return username;
    }
    public void setUsername(String username) {
    this.username = username;
    }

    }
    My ActionForm Class is

    package org.deepak.connect;

    import javax.servlet.http.HttpServletResponse;

    import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.ActionMessage;

    public class TableForm extends ActionForm{

    /**
    *
    */
    private static final long serialVersionUID = 5365417534660856624L;
    private String userid;
    private String username;

    public String getUserid() {
    return userid;
    }
    public void setUserid(String userid) {
    this.userid = userid;
    }
    public String getUsername() {
    return username;
    }
    public void setUsername(String username) {
    this.username = username;
    }

    public ActionErrors validate(ActionMapping mapping, HttpServletResponse response){
    ActionErrors errors = new ActionErrors();
    if(getUserid().trim().isEmpty()||getUsername().trim().isEmpty()){
    errors.add("userid", new ActionMessage("com.error.userid.blank"));
    }

    return errors;
    }

    }
    but still I am not able to Insert the value supplied by my Jsp file JSP code is:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

    <html:form action="/Reguser.do">
    <table>
    <tr><td>
    User Id:<html:text property="userid" size="20"/>
    <html:errors name="userid"/>
    </td></tr>
    <tr><td>
    User Name:<html:text property="username" size="20"/>
    <html:errors name="userid"/>
    <tr><td>
    <html:submit/>
    </td></tr>
    </table>
    </html:form>

    Please tell me how to proceed.
    Sandy Chatterjee
    Ranch Hand

    Joined: Jun 27, 2012
    Posts: 55

    but still I am not able to Insert the value supplied by my Jsp file

    You won't be able to because

    In line no. 8 you have written

    It's creating a new instance of TableForm. What you need to do is

    As for each action a unique thread is generated and the value of the Action Form Bean is passed as a parameter to the execute(....) method.
    Then you have to downcast it to Tableform class to get it's values.

    See if it works. If it doesn't supply me all the details. Like struts-config.xml, hiebernate.cfg.xml.
    Also use the code tag on top to mark the codes before submitting as it looks better.

    Regards,
    Sandy
    D. Deepak Sharma
    Ranch Hand

    Joined: May 12, 2012
    Posts: 31
    See if it works. If it doesn't supply me all the details. Like struts-config.xml, hiebernate.cfg.xml.
    Also use the code tag on top to mark the codes before submitting as it looks better


    Yes Oh! thanks Sir guess did pay full attention. But after doing changes I couldn't run the code I am forwarding the said codes of sturts-config.xml and hibernate.cfg.xml

    hibernate.cfg.xml


    struts-config.xml



    I am also putting the detailed Logs I am getting after I press submit button.

    Jun 30, 2012 9:05:25 AM org.apache.catalina.core.AprLifecycleListener init
    INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.7.0_04\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;.
    Jun 30, 2012 9:05:25 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
    WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StrutsExample' did not find a matching property.
    Jun 30, 2012 9:05:25 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
    WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:RegistrationForm' did not find a matching property.
    Jun 30, 2012 9:05:25 AM org.apache.coyote.http11.Http11Protocol init
    INFO: Initializing Coyote HTTP/1.1 on http-8080
    Jun 30, 2012 9:05:25 AM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 824 ms
    Jun 30, 2012 9:05:25 AM org.apache.catalina.core.StandardService start
    INFO: Starting service Catalina
    Jun 30, 2012 9:05:25 AM org.apache.catalina.core.StandardEngine start
    INFO: Starting Servlet Engine: Apache Tomcat/6.0.35
    Jun 30, 2012 9:05:26 AM org.apache.struts.action.ActionServlet initChain
    INFO: Loading chain catalog from jar:file:/L:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/RegistrationForm/WEB-INF/lib/struts-core-1.3.10.jar!/org/apache/struts/chain/chain-config.xml
    Jun 30, 2012 9:05:27 AM org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
    INFO: Tiles definition factory loaded for module ''.
    380 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
    390 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.10.Final
    390 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
    406 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
    406 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
    576 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
    576 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
    626 [main] WARN org.hibernate.util.DTDEntityResolver - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
    693 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
    903 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.deepak.hbn.test.HibernateTest
    993 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.deepak.hbn.test.HibernateTest on table HibernateTest
    1103 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.deepak.hbn.retrieve.DataRetrival
    1103 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.deepak.hbn.retrieve.DataRetrival on table DataRetrival
    1103 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: org.deepak.connect.CreatingTable
    1103 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity org.deepak.connect.CreatingTable on table CreatingTable
    1113 [main] INFO org.hibernate.cfg.Configuration - Hibernate Validator not found: ignoring
    1133 [main] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
    1143 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
    1143 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 2
    1143 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
    1163 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.apache.derby.jdbc.ClientDriver at URL: jdbc:derby://localhost:1527/Hibernate;create=true
    1163 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=user, password=****}
    1443 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.DerbyDialect
    1575 [main] INFO org.hibernate.cfg.SettingsFactory - Database ->
    name : Apache Derby
    version : 10.8.2.2 - (1181258)
    major : 10
    minor : 8
    1575 [main] INFO org.hibernate.cfg.SettingsFactory - Driver ->
    name : Apache Derby Network Client JDBC Driver
    version : 10.8.2.2 - (1181258)
    major : 10
    minor : 8
    1575 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
    1585 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    1585 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
    1585 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
    1585 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
    1585 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): disabled
    1585 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
    1585 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
    1585 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
    1585 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
    1585 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
    1585 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    1595 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
    1595 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
    1595 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
    1595 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
    1595 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
    1595 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
    1595 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
    1595 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
    1605 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
    1615 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
    1615 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
    1615 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
    1615 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
    1615 [main] INFO org.hibernate.cfg.SettingsFactory - Check Nullability in Core (should be disabled when Bean Validation is on): enabled
    1655 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
    1675 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@3ed9ba
    1675 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [blob] overrides previous : org.hibernate.type.BlobType@485d22
    1675 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@485d22
    1675 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [clob] overrides previous : org.hibernate.type.ClobType@da6874
    1675 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@da6874
    1675 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@ffa25e
    1675 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@fcd103
    1675 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@1fe3515
    1675 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType@4f092f
    2105 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
    2115 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
    2115 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
    2705 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - schema export complete
    Jun 30, 2012 9:05:30 AM org.apache.struts.action.ActionServlet initChain
    INFO: Loading chain catalog from jar:file:/L:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/StrutsExample/WEB-INF/lib/struts-core-1.3.10.jar!/org/apache/struts/chain/chain-config.xml
    Jun 30, 2012 9:05:30 AM org.apache.coyote.http11.Http11Protocol start
    INFO: Starting Coyote HTTP/1.1 on http-8080
    Jun 30, 2012 9:05:31 AM org.apache.jk.common.ChannelSocket init
    INFO: JK: ajp13 listening on /0.0.0.0:8009
    Jun 30, 2012 9:05:31 AM org.apache.jk.server.JkMain start
    INFO: Jk running ID=0 time=0/20 config=null
    Jun 30, 2012 9:05:31 AM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 5223 ms
    [b]Jun 30, 2012 9:05:37 AM org.apache.struts.chain.ComposableRequestProcessor init
    INFO: Initializing composable request processor for module prefix ''
    Jun 30, 2012 9:05:37 AM org.apache.struts.chain.commands.servlet.CreateAction createAction
    INFO: Initialize action of type: org.deepak.connect.TableStrutsAction
    Jun 30, 2012 9:05:37 AM org.apache.struts.util.PropertyMessageResources loadLocale
    WARNING: Resource org/apache/struts/action/LocalStrings_en_US.properties Not Found.
    Jun 30, 2012 9:05:37 AM org.apache.struts.util.PropertyMessageResources loadLocale
    WARNING: Resource org/apache/struts/action/LocalStrings_en.properties Not Found.
    [/b]
    Sandy Chatterjee
    Ranch Hand

    Joined: Jun 27, 2012
    Posts: 55

    I have made a few changes in your code and it's running fine in my system.

    changed the package name to sand from org.deepak.connect and also if you are using
    annotations use new AnnotationConfiguration().configure().createSessionFactory()


    Here are the codes:

    hibernate.cfg.xml (Mine is for MySql but you can use Dbderby)


    struts-config.xml


    TableStrutsAction.java (Inside 'Action' package)

    TableForm.java (In 'Form' package)

    In sand package
    CreatingTable.java

    In sand package
    HibernatePlugin.java

    deepak.jsp
    in deepak folder

    index.jsp

    Its running fine in my system. See if it runs on yours. Please give me the feedback as soon as possible.
    Sandy Chatterjee
    Ranch Hand

    Joined: Jun 27, 2012
    Posts: 55

    Do not make any changes.
    Paste the code as it is.
    Sandy Chatterjee
    Ranch Hand

    Joined: Jun 27, 2012
    Posts: 55

    One more thing please create the database by yourself
    and one the table is created for the first time change

    to
    D. Deepak Sharma
    Ranch Hand

    Joined: May 12, 2012
    Posts: 31
    Sir I pasted the same code as you said to me but still the outcome is same when i enter the value in the form well the Index.jsp is not running means does not forward to deepak.jsp and When I run deepak.jsp directly it enters the values in the fields the values are passed to the action form and this warning message is shown
    but then redirect me to error.jsp.
    Sandy Chatterjee
    Ranch Hand

    Joined: Jun 27, 2012
    Posts: 55

    Do one thing start a completely new project. Then paste these codes.
    Still if it doesn't work try removing the entire code from HibernatePlugin, i.e

    from struts-config.xml and try running it.
    Just do it and provide me the feedback I am online.
    The code has no errors as I have tested the entire code in my system and then posted it.
    The only that doesn't match is the database.
    I am using MySql and you are using DbDerby.
    Sandy Chatterjee
    Ranch Hand

    Joined: Jun 27, 2012
    Posts: 55

    Change the package names as well.

    The same package name I have specified. Then it will be easier for me to find the root cause.
    D. Deepak Sharma
    Ranch Hand

    Joined: May 12, 2012
    Posts: 31
    Yes Sir It Worked thanks

    But sir what if i want to move this coding to a Model Class I tried to write a model where i can create all the SessionFactory and all the Hibernate call and then call a simple function in my action class. Let me tell you what i wrote in my Model class.



    Let me tell what is the main problem I am facing
  • How to get ServletContext in model class that we used in Action Class
  • Can I write more than one action Class to handle the form and/or web application request
  • Is it must to use AnnotationConfiguration because I used the same AnnotationConfiguration object initially instead of Simple Configuration object but it showed the message that it has been depricrated" so please tell me what is difference between them and which one is the best practice to use the right configuration
  • Is there anyother way to implement the same example without HibernatePlugin

  • Thanks and Regards
    Sandy Chatterjee
    Ranch Hand

    Joined: Jun 27, 2012
    Posts: 55

    Its good that your code is running fine.
    Just for testing change the package name to org.deepak.connect from sand in which the HibernatePlugin.java resides.
    Change it in struts-config.xml as well and see if your program still runs or not.

    Answering your questions:

    How to get ServletContext in model class that we used in Action Class


    Its not at all a good practice to put web related stuff in your Model object. As some other day if you want to
    use some language other than java you cannot.
    So, keep your model clean.

    But then the question arises how can you use the model class to save or retrieve data?
    Answer is all the web related stuff should be in the Action class and not outside that.

    Use the HibernateUtils class in the Action class and then call the model class method to persist it to the database.

    Can I write more than one action Class to handle the form and/or web application request


    For handling a single action we use a single Action class and a single ActionForm.
    But if you tell me what exactly you are trying to do then I can think.

    Is it must to use AnnotationConfiguration because I used the same AnnotationConfiguration object initially instead of Simple Configuration object but it showed the message that it has been depricrated" so please tell me what is difference between them and which one is the best practice to use the right configuration


    Normally I don't use Annotations in Hibernate so I cannot tell you exactly why. An error was shown by my IDE
    so I used AnnotationConfiguration object.

    Is there anyother way to implement the same example without HibernatePlugin


    Yes there is, just use the HibernateUtils.java to create the SessionFactory as well. But in that case every time you have to
    create an instance of SessionFactory before using it.
    The trick is declare the SessionFactory object creation in a static block.
    So, when the HibernateUtils class is loaded by the JVM for the first time SessionFactory instance will
    be created and its created only once.
    If you have any problem in understanding just reply back I'll post the codes.

    Also I have a question for you:
    How did you access the 'servlet' object from the Action class?
    SessionFactory factory = (SessionFactory)servlet.getServletContext().getAttribute(HibernatePlugin.KEY_NAME);


    Regards,
    Sandy
    D. Deepak Sharma
    Ranch Hand

    Joined: May 12, 2012
    Posts: 31
    Its good that your code is running fine.
    Just for testing change the package name to org.deepak.connect from sand in which the HibernatePlugin.java resides.
    Change it in struts-config.xml as well and see if your program still runs or not.

    Sir I tried my whole day in doing the same initially there was the same error i reported earlier but I spent a lot of time in doing the research actually today i was working on different system at the end I simply used the same code as well as same package name but I am tired of same error


    here i did not modify anything as suggested I could not figured out what exactly went wrong
    Answering your questions:

    Can I write more than one action Class to handle the form and/or web application request

    Sir I am trying to say that Suppose there is one Action Class and there suppose 3 forms then can i handle all 3 forms in same action class and can manipulate the forms data using multiple Model Classes and Forward the mapping to corresponding views.

    writing more clear

    suppose there are 3 forms say A B and C now there is one Action Class ActionC now what I am saying suppose there is situation when one form is submitting its data and 2 are not then how the execute() function would execute and and then other 2 forms are sending its data and first one is not submitting then will this ActionC class service these forms simultaneous.

    Also I have a question for you:
    How did you access the 'servlet' object from the Action class?
    SessionFactory factory = (SessionFactory)servlet.getServletContext().getAttribute(HibernatePlugin.KEY_NAME);


    Sir the Action class inherits ActionServlet Class therefore we could use the servlet object but there is little confusion that in HibernatePlugin class in init() method the first object was ActionServlet what if we change the name of the argument say arg0 but still we can access the servlet object using servlet.getServletContext()....etc mean is it always have servlet name by default. but when i tried the same technique in my previous model class where i pass the value of 2 variables and one ActionServlet object but I still was not able to get the ServletContext()...etc. please clear my concept.

    Regards,
    Deepak
    Sandy Chatterjee
    Ranch Hand

    Joined: Jun 27, 2012
    Posts: 55

    I tried my whole day in doing the same initially there was the same error i reported earlier but I spent a lot of time in doing the research actually today i was working on different system at the end I simply used the same code as well as same package name but I am tired of same error

    Are you trying to start a new project or you have pasted the code in the existing project.
    From the messages it seems there is a problem reading the MessagesResources. It tough to conclude just by looking the messages.

    Suppose there is one Action Class and there suppose 3 forms then can i handle all 3 forms in same action class and can manipulate the forms data using multiple Model Classes and Forward the mapping to corresponding views

    No so sure about this. You can try the following.
    You should have three ActionMappings.
    In the three forms FormA, FormB and FormC add two Strings also the three form should implement an interface BaseForm(Which actually inherits ActionForm):
    String formName;
    String formSubmit;
    Initialize formName with 'A', 'B' and 'C' form the three forms in the ActionForm itself.
    And initialize formSubmit with 'true'.

    I your JSP put the above strings as hidden form parameters.

    So, there are three forms and one Action ActionC.
    In the execute() method of the Action class do the following:


    Action class inherits ActionServlet Class therefore we could use the servlet object

    Thanks I got the answer.
    but when i tried the same technique in my previous model class where i pass the value of 2 variables and one ActionServlet object but I still was not able to get the ServletContext()...etc. please clear my concept

    I have to think a bit a we don't use Web related stuff in the Model.

    Regards,
    Sandy
    D. Deepak Sharma
    Ranch Hand

    Joined: May 12, 2012
    Posts: 31
    Are you trying to start a new project or you have pasted the code in the existing project.
    From the messages it seems there is a problem reading the MessagesResources. It tough to conclude just by looking the messages.


    Sir actually I committed one mistake back there that when I was putting all the classes in same package or as you wrote the code it forgot to change the hibernate.cfg.xml file where mapping class remained some I don't know whatever class when I saw the whole code thoroughly then I found the base of that error.

    I have putted whole classes in same package and they are working fine.

    Regards,
    Deepak
    D. Deepak Sharma
    Ranch Hand

    Joined: May 12, 2012
    Posts: 31
    Is there anyother way to implement the same example without HibernatePlugin


    Yes there is, just use the HibernateUtils.java to create the SessionFactory as well. But in that case every time you have to
    create an instance of SessionFactory before using it.
    The trick is declare the SessionFactory object creation in a static block.
    So, when the HibernateUtils class is loaded by the JVM for the first time SessionFactory instance will
    be created and its created only once.
    If you have any problem in understanding just reply back I'll post the codes.


    Sir I don't understand what exactly to do because you have already declared SessionFactory object in static block in HibernateUtil class, so If i am thinking right then we will implement the init() method in Action class instead of HibernatePlugin class mean will remove HibernatePlugin from the picture.
    Please paste the code If I am wrong otherwise I will show you what i wrote.

    Regards,
    Deepak
    Sandy Chatterjee
    Ranch Hand

    Joined: Jun 27, 2012
    Posts: 55

    HibernateUtils.java


    From line number 15 to 22 I have created the SessionFactory object in a static block.
    The static block will be called only once when the class is loaded into the jvm. Which means SessionFactory object will be created only once.
    Now, remove the HibernatePlugin as we don't need that anymore because the SessionFactory is created in the HibernateUtils class.

    Regards,
    Sandy
    D. Deepak Sharma
    Ranch Hand

    Joined: May 12, 2012
    Posts: 31
    Dear Sir,

    Due to some technical glitches right now I am not able to work further for 1 - 2 days so give me a day or 2 so that i can further proceed with our project.

    Thanks and Regards,

    Deepak
    D. Deepak Sharma
    Ranch Hand

    Joined: May 12, 2012
    Posts: 31
    D. Deepak Sharma
    Ranch Hand

    Joined: May 12, 2012
    Posts: 31
    Sir after writing the static function it ran,

  • Now sir how to render the rows of the resultset
  • How to edit my rows or column data using struts and model classes mean display on jsp page or show the result by retrieving the selected rows or columns


  • Thanks and Regards,
    Deepak Sharma
    D. Deepak Sharma
    Ranch Hand

    Joined: May 12, 2012
    Posts: 31
    Sir,

    I have one more last question for the day that if you have noticed that in our HibernateUtils.class we have a function called createSession() but when it comes to use that function in our action class we simply call the openFactory()/createFactory() function and then use that typecasted object for creating new connection/ to use openSession() menthod and that Thread safe session instance remain unused as that creatSession() is never called in action class, Is there any flaw in what I am saying please Sir, clearify me!

    Regards,
    Deepak
    Sandy Chatterjee
    Ranch Hand

    Joined: Jun 27, 2012
    Posts: 55

    I'll get back to you shortly. Little busy now.

    Regards,
    sandy
    Sandy Chatterjee
    Ranch Hand

    Joined: Jun 27, 2012
    Posts: 55

    Hi,

    I am back.
    in our HibernateUtils.class we have a function called createSession() but when it comes to use that function in our action class we simply call the openFactory()/createFactory() function and then use that typecasted object for creating new connection/ to use openSession() menthod and that Thread safe session instance remain unused as that creatSession() is never called in action class

    In the above example we have not used the HibernateUtils.java. If you check the Action class you will not find any import statement for HibernateUtils.java.
    So, don't be confused. Its by mistake I have pasted the code for HibernateUtils.java.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown.