0 Replies Latest reply on Mar 22, 2007 9:30 AM by omar trifa

    Hibernate JBoss

    omar trifa Newbie

      Dear,

      I m develpping a web application using JBoss4, eclipse3.2, MySQL, Hibernate3
      I'm new with Hibernate. so that i have a probelm to deploy it in JBoss.

      I developed a simple example(from internet) and add its hibernate to see if its ok or not. (one page html and 2 jsp)

      GetName.html



      <FORM METHOD=POST ACTION="SaveName.jsp">
      Registration
      Username : <INPUT TYPE=TEXT NAME=username SIZE=20 align="top">
      Password : <INPUT TYPE=PASSWORD NAME=password SIZE=20>
      Confirm your password : <INPUT TYPE=PASSWORD NAME=confirmpass SIZE=20>
      <INPUT TYPE=SUBMIT name="register" value="Register">




      SaveName.jsp

      <%@page import="org.hibernate.Session" %>
      <%@page import="org.hibernate.Transaction" %>
      <%@page import="roseindia.tutorial.hibernate.*" %>

      <%
      Session sessionn = HibernateUtil.currentSession();
      Transaction tx = sessionn.beginTransaction();
      Contact user = new Contact();

      String username = request.getParameter( "username" );
      session.setAttribute( "username", username );

      String password = request.getParameter( "password" );
      session.setAttribute( "password", password );

      String confirmpass = request.getParameter( "confirmpass" );
      String message=null ;
      if (!password.equals(confirmpass))
      message = "Please verify your password" ;

      session.setAttribute("message", message);

      user.setFirstName("nachnouch");
      sessionn.save(user);
      tx.commit();
      HibernateUtil.closeSession();
      %>




      <% if (password.equals(confirmpass)) { %>
      Continue
      <% } else { %>
      Continue
      <% } %>



      NextPage.jsp




      Hello, <%= session.getAttribute( "username" ) %>
      Your password is "<%= session.getAttribute( "password" ) %>"



      hibernate.cfg.xml

      <?xml version='1.0' encoding='utf-8'?>
      <!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

      <hibernate-configuration>
      <session-factory>
      com.mysql.jdbc.Driver
      jdbc:mysql://localhost/hibernatetutorial
      root
      root
      10
      true
      org.hibernate.dialect.MySQLDialect
      update
      <!-- Mapping files -->

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

      Contact.hbm.xml

      <?xml version="1.0"?>
      <!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
      <hibernate-mapping>
















      </hibernate-mapping>

      Contact.java

      package roseindia.tutorial.hibernate;

      /**
      * @author Deepak Kumar
      *
      * http://www.roseindia.net
      * Java Class to map to the datbase Contact Table
      */
      public class Contact {
      private String firstName;
      private String lastName;
      private String email;
      private long id;

      /**
      * @return Email
      */
      public String getEmail() {
      return email;
      }

      /**
      * @return First Name
      */
      public String getFirstName() {
      return firstName;
      }

      /**
      * @return Last name
      */
      public String getLastName() {
      return lastName;
      }

      /**
      * @param string Sets the Email
      */
      public void setEmail(String string) {
      email = string;
      }

      /**
      * @param string Sets the First Name
      */
      public void setFirstName(String string) {
      firstName = string;
      }

      /**
      * @param string sets the Last Name
      */
      public void setLastName(String string) {
      lastName = string;
      }

      /**
      * @return ID Returns ID
      */
      public long getId() {
      return id;
      }

      /**
      * @param l Sets the ID
      */
      public void setId(long l) {
      id = l;
      }

      }


      HibernateUtil.java

      package roseindia.tutorial.hibernate;

      import org.hibernate.*;
      import org.hibernate.cfg.Configuration;

      public class HibernateUtil {

      private static final SessionFactory sessionFactory;

      static {
      try {
      // Crée la SessionFactory
      sessionFactory =
      new Configuration().configure().buildSessionFactory();
      } catch (HibernateException ex) {
      throw new RuntimeException("Problème de configuration : "
      + ex.getMessage(), ex);
      }
      }

      public static final ThreadLocal session = new ThreadLocal();

      public static Session currentSession()
      throws HibernateException {
      Session s = (Session) session.get();
      // Ouvre une nouvelle Session, si ce Thread n'en a aucune
      if (s == null) {
      s = sessionFactory.openSession();
      session.set(s);
      }
      return s;
      }

      public static void closeSession()
      throws HibernateException {
      Session s = (Session) session.get();
      session.set(null);
      if (s != null)
      s.close();
      }
      }


      and when i run on server i have this message

      13:34:56,646 INFO [Server] JBoss (MX MicroKernel) [4.0.5.GA (build: CVSTag=Branch_4_0 date=200610162339)] Started in 33s:832ms
      13:42:01,113 INFO [Environment] Hibernate 3.2.0.ga
      13:42:01,133 INFO [Environment] hibernate.properties not found
      13:42:01,143 INFO [Environment] Bytecode provider name : cglib
      13:42:01,153 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
      13:42:01,394 INFO [Configuration] configuring from resource: /hibernate.cfg.xml
      13:42:01,394 INFO [Configuration] Configuration resource: /hibernate.cfg.xml
      13:42:01,464 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
      java.lang.ExceptionInInitializerError
      at org.apache.jsp.SaveName_jsp._jspService(SaveName_jsp.java:51)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Unknown Source)
      Caused by: java.lang.RuntimeException: Problème de configuration : /hibernate.cfg.xml not found
      at roseindia.tutorial.hibernate.HibernateUtil.(HibernateUtil.java:17)
      ... 26 more
      Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found
      at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
      at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1329)
      at org.hibernate.cfg.Configuration.configure(Configuration.java:1351)
      at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
      at roseindia.tutorial.hibernate.HibernateUtil.(HibernateUtil.java:15)
      ... 26 more



      I need help to resolve this problem

      THANK YOU