-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Help required in Using Hibernate in Axis2 / Tomcat !!
PostPosted: Wed Feb 18, 2009 11:35 am 
Newbie

Joined: Wed Feb 18, 2009 10:44 am
Posts: 3
I am new to Hibernate with axis2 in tomcat..

I am unable to initiate session.Please help me.I am giving my full code here.I am trying from 2 days.
I included all dependent jars in axis2/lib and hibernate config and mapping files in axis2/classes


Following is the error log
[INFO] configuring from resource: /hibernate.cfg.xml
[INFO] Configuration resource: /hibernate.cfg.xml
[INFO] Mapping resource: testtableMapping.hbm.xml
[INFO] Mapping class: ch.elca.des.testwebservice.testService -> "testtable"
[INFO] Configured SessionFactory: null
[INFO] processing extends queue
[INFO] processing collection mappings
[INFO] processing association property references
[INFO] processing foreign key constraints
[INFO] Using dialect: org.hibernate.dialect.PostgreSQLDialect
[INFO] Default batch fetch size: 1
[INFO] Generate SQL with comments: disabled
[INFO] Order SQL updates by primary key: disabled
[INFO] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
[INFO] Using ASTQueryTranslatorFactory
[INFO] Query language substitutions: {}
[INFO] Using Hibernate built-in connection pool (not for production use!)
[INFO] Hibernate connection pool size: 10
[INFO] autocommit mode: false
[INFO] using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/DESDB
[INFO] connection properties: {user=DES, password=****}
[INFO] JDBC batch size: 15
[INFO] JDBC batch updates for versioned data: disabled
[INFO] Scrollable result sets: enabled
[INFO] JDBC3 getGeneratedKeys(): disabled
[INFO] Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
[INFO] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
[INFO] Automatic flush during beforeCompletion(): disabled
[INFO] Automatic session close at end of transaction: disabled
[INFO] Cache provider: org.hibernate.cache.EhCacheProvider
[INFO] Second-level cache: enabled
[INFO] Optimize cache for minimal puts: disabled
[INFO] Structured second-level cache entries: enabled
[INFO] Query cache: disabled
[INFO] Echoing all SQL to stdout
[INFO] Statistics: disabled
[INFO] Deleted entity synthetic identifier rollback: disabled
[INFO] Default entity-mode: pojo
[INFO] building session factory
Initial SessionFactory creation failed.java.lang.NullPointerException
[ERROR]
org.apache.axis2.AxisFault
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at ch.elca.des.testwebservice.TestMessageReceiverInOut.invokeBusinessLogic(TestMessageReceiverInOut.java:65)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:100)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:176)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:133)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:857)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at ch.elca.des.testwebservice.testDBDAO.InsertRow(testDBDAO.java:39)
at ch.elca.des.testwebservice.testWService.GenerateName(testWService.java:12)
at ch.elca.des.testwebservice.TestSkeleton.insert(TestSkeleton.java:35)
at ch.elca.des.testwebservice.TestMessageReceiverInOut.invokeBusinessLogic(TestMessageReceiverInOut.java:51)
... 19 more

-----------------------------

hibernate.cfg.xml
Code:
<?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>
      <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
      <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/DESDB</property>
      <property name="hibernate.connection.username">DES</property>
      <property name="hibernate.connection.password">hello</property>
      <property name="hibernate.connection.pool_size">10</property>
      <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
     <property name="current_session_context_class">thread</property>
     <property name="show_sql">true</property>
      <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
      <!-- Mapping files -->
      <mapping resource="testtableMapping.hbm.xml"/>
     
</session-factory>
</hibernate-configuration>



testtableMapping.hbm.xml

Code:

<?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 schema="&quot;public&quot;" >
  <class name="ch.elca.des.testwebservice.testService" table='"testtable"'>
      <id name="age" type="int" column='"age"' >
      </id> 
     <property name="name" type="java.lang.String">
       <column name='"name"' not-null="true"/>
     </property>
    
   </class>
</hibernate-mapping>




Code testDBDAO.java

Code:
package ch.elca.des.testwebservice;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class testDBDAO {
   
   public testDBDAO(){
      
   }
   
   public  void InsertRow(testService t){
      Session session = null;

      try{
         
         session =  HibernateUtil.getSessionFactory().openSession();
         if(session!=null)
            System.out.println("session opened");
      
         System.out.println("Inserting a new Record in testtable");
         System.out.println("-----------------------");
         Transaction tx = null;   
         try{
            tx=session.beginTransaction();
            session.save(t);
         }catch(Exception e){
            if(tx!=null)
               tx.rollback();
            throw e;
         }
         tx.commit();
         
        }catch(Exception e){
         System.out.println(e.getMessage());
       }finally{
          session.flush();
          session.close();      
       }
   }
   
}


Code HibernateUtil.java

Code:
package ch.elca.des.testwebservice;

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


public class HibernateUtil {

   
   private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

   
}


Code for testWService.java
Code:
package ch.elca.des.testwebservice;

public class testWService{

   public String GenerateName(int age) {
   
      testService t = new testService();
         t.setage(age);
         t.setname("Hello");
         System.out.println(t.getage() + t.getname());
      testDBDAO td = new testDBDAO();
      td.InsertRow(t);
         System.out.println("age = "+age);
         return t.getname();
   }
         
}


Code testService.java
Code:
package ch.elca.des.testwebservice;

public class testService{

   private String name;
   private int age;
   
   //GETTER  METHODS IMPLEMENTED
   
  public testService(){};
  public String getname() {
     return name;
  }
  public int getage(){
     return age;
  }
    //SETTER METHODS IMPLEMENTED
 
  public void setname(String var) {
      name = var;
  }
  public void setage(int var) {
    age = var;
  }
 
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.