-->
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.  [ 2 posts ] 
Author Message
 Post subject: NullPointer Exception on Hibernate Inicialization
PostPosted: Wed May 05, 2010 1:32 pm 
Newbie

Joined: Wed May 05, 2010 1:21 pm
Posts: 1
Hello, i am fairly new to hibernate and have been having some problems to inicialize hibernate. I tried using spring but had some problems to integrate with hibernate search so i decided to fall back to pure hibernate. I got this HibernateUtil class which inicializes the following way:
Code:
public static void initialize()
    {
        try
        {
            sessionFactory = configuration.configure().buildSessionFactory();
            System.out.println( ">>Sucess MSG" );
        }
        catch ( Throwable e )
        {
           System.out.println( ">> Fail MSG" );
           e.printStackTrace();
        }
    }



my hibernate.cfg.xml is in the root directory (i dont know how to add it to classpath on netbeans [it was self generated])
Code:
<hibernate-configuration>
  <session-factory name="session">
    <!-- Username utilizado no BD -->
    <property name="hibernate.connection.username">root</property>
    <!-- Senha utilizado no BD -->
    <property name="hibernate.connection.password">root</property>
    <!-- Chamada de URL ou string de conexao, deve ser configurado de acordo com documentacao do banco de dados -->
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/clio-j</property>
    <!-- Driver que deve ser utilizado -->
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <!-- Dialeto a ser utilizado para a comunicacao com o banco de dados -->
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <!-- Como o hibernate vai se comportar em relacao as tabelas do banco. Com o update ele vai criar ou modificar tabelas sempre que necessario. -->
    <property name="hibernate.hbm2ddl.auto">update</property>
    <!-- Flag que indica se os SQLs gerados devem ser impressos -->
    <property name="show_sql">true</property>
    <!-- Flag que indica se os SQLs devem ser formatados-->
    <property name="format_sql">true</property>
    <!-- Flag que indica que a configuracao do hibernate deve ser gerenciada automaticamente -->
    <property name="hibernate.current_session_context_class">thread</property>
    <!-- Informando ao Hibernate sobre a classe existente -->
    <mapping class="br.ufpe.liber.clioj.dominio.Administrador"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Audio"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Colecao"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Documento"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Grupo"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Historico"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Imagem"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Local"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Notas"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Permissao"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Refinemento"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Texto"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Usuario"/>
    <mapping class="br.ufpe.liber.clioj.dominio.Video"/>
   
  </session-factory>
</hibernate-configuration>


and here is the stacktrace for the error
Code:
INFO: >> Fail MSG
SEVERE: java.lang.NullPointerException
        at br.ufpe.liber.clioj.util.hibernate.HibernateUtil.initialize(HibernateUtil.java:42)
        at br.ufpe.liber.clioj.util.hibernate.HibernateUtil.getSession(HibernateUtil.java:116)
        at br.ufpe.liber.clioj.dao.hibernate.DocumentoDaoImpl.<init>(DocumentoDaoImpl.java:21)
        at org.apache.jsp.admin.cadastroHandler_jsp._jspService(cadastroHandler_jsp.java from :69)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:406)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:483)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:373)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
        at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
        at java.lang.Thread.run(Thread.java:619)


thanks in advance!

pst im completly new to this so try to be as explanatory as possible thanks =D.


oooo almost forgot, here's getSession()
Code:
public static Session getSession()
    {
       if( sessionFactory == null ){
          initialize();
          closeSession();
       }

        Session s = (Session) threadSession.get();
        if ( s == null )
        {
            s = sessionFactory.openSession();
            threadSession.set( s );
        }
        return s;
    }


Top
 Profile  
 
 Post subject: Re: NullPointer Exception on Hibernate Inicialization
PostPosted: Thu May 06, 2010 2:32 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
well there's a NullPointerException happening in your own code, it says on line 42, but you're the only one able to tell what that line is.

_________________
Sanne
http://in.relation.to/


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

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.