-->
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: Mapping resource tag generating nullpointerexception
PostPosted: Fri Oct 08, 2010 12:23 pm 
Newbie

Joined: Fri Sep 03, 2010 10:51 am
Posts: 4
Hi,
Adding mapping resource tag to the hibernate config file throws the following stacktrace:
Code:
Root cause of ServletException.
javax.el.ELException: java.lang.NullPointerException
   at javax.el.BeanELResolver.getValue(BeanELResolver.java:266)
   at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
   at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
   at com.sun.el.parser.AstValue.getValue(AstValue.java:118)
   at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)
   Truncated. see log file for complete stacktrace

Caused By: java.lang.NullPointerException
   at test.hib.backing.UserRegistration.getSplist(UserRegistration.java:112)
   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)


On debugging, found that the error was generated when creating a session factory in the following code. This is an accessor method bound to a dropdown menu. It is populated when the page is loaded.
Code:
    public UISelectItems getSplist() {
      Session SPsess=null;
      try
      {
      System.out.println("getsplist");       
      SPsess = SessionFac.getSessionFactory().openSession();--error generating line of code.
      ArrayList spstr = new ArrayList();
      spstr = (ArrayList)SPsess.createSQLQuery(spqry).list();
      ArrayList splistsi = new ArrayList();
      Iterator spitr = spstr.iterator();
        while(spitr.hasNext())
        {         
            splistsi.add(new SelectItem(spitr.next()));     
        }
      splist = new UISelectItems();
      splist.setValue(splistsi);
      }
      catch(Exception e)
      {     
      System.out.println(e.getMessage());
      System.out.println(spqry);
      }
      finally
      {
        SPsess.close();
      }
        return splist;
    }


Hibernate config file. This file is located in the class directory, while the mapping files are in the source directories where their associated java files are.
Code:
<?xml version="1.0" encoding="windows-1252" ?>
<!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="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:sid</property>
<property name="hibernate.connection.username">xyz</property>
<property name="hibernate.connection.password">xyz</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.cache.region.factory_class">
net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">50</property>
<mapping resource="/test/hib/entities/ServiceRecordInfo.hbm.xml"/>   
<mapping resource="/test/hib/entities/CompanyInfo.hbm.xml"/>
</session-factory>
</hibernate-configuration>



Session factory singleton class called in the accessor method:
Code:
public class SessionFac {
   
  private static final SessionFactory sessionFactory = buildSessionFactory();

  private static SessionFactory buildSessionFactory()
      {
          try{
              return (new Configuration()).configure().buildSessionFactory();
          }
          catch(ExceptionInInitializerError ex)
          {
              System.err.println((new StringBuilder()).append("Initial SessionFactory creation failed.").append(ex).toString());
              throw new ExceptionInInitializerError(ex);
          }
      }

      public static SessionFactory getSessionFactory()
      {
          return sessionFactory;
      }

      public Session openSession()
      {
          return sessionFactory.openSession();
      }


}

Any idea why this error is being thrown?

Thanks.


Top
 Profile  
 
 Post subject: Re: Mapping resource tag generating nullpointerexception
PostPosted: Sun Oct 10, 2010 9:28 am 
Regular
Regular

Joined: Sun Feb 14, 2010 3:29 pm
Posts: 58
Location: USA
So what's on "test.hib.backing.UserRegistration.java" line 112?

You likely have an object that's uninitialized on that line. If it's caused by hibernate mapping config, you should able to trace your stack trace to the exact error. Show your complete stacktrace.

_________________
Zemian Deng
------------
Need a Java Scheduler? Try
http://bitbucket.org/timemachine/scheduler


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.