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.