Hello
I have a small application using Spring 3 and Hibernate 4 with JSF2, When I am running the application I am getting.
What am I doing wrongly to get **nullpointer exception**? Any help is highly appreciable.Code:java.lang.NullPointerException at net.test.managed.bean.EmployeesManagedBean.getEmpList(EmployeesManagedBean.java:53)
Thanks
ManagedBean:
and I have Inject annotation:Code:@Named("empMB") @Scope("request") public class EmployeesManagedBean implements Serializable { @Inject IEmployeesService employeesService; public List<Employees> getEmpList() { try { empList = new ArrayList<Employees>(); empList.addAll(getEmployeesService().getEmployees()); } catch (Exception e) { e.printStackTrace(); } return empList; } }
In EmployeesService I have annotations like:
In EmployeesDAO I have annotations like:Code:@Transactional(readOnly = true) @Named public class EmployeesService implements IEmployeesService { @Inject IEmployeesDAO employeesDAO; @Override public List<Employees> getEmployees() { return getEmployeesDAO().getEmployees(); }
Entity class:Code:@Named public class EmployeesDAO implements IEmployeesDAO { @Override public List<Employees> getEmployees() { List query = this.getSessionFactory().getCurrentSession().getNamedQuery("getEmp").list(); return query; }
and finally in applicationContext.xml I haveCode:@Entity @javax.persistence.NamedNativeQuery(name = "getEmp", query = "{ ? = call getemployees }", resultClass = Employees.class, hints = { @javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") }) @Table(name = "EMPLOYEES") public class Employees {
Code:<context:component-scan base-package="net.test" />
applicationContext.xml:
StacktraceCode:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="net.test" /> <!-- Data Source Declaration --> <bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="oracle.jdbc" /> <property name="jdbcUrl" value="jdbc:oracle:thin:@server:1521:DEV" /> <property name="user" value="scott" /> <property name="password" value="tiger" /> <property name="maxPoolSize" value="10" /> <property name="maxStatements" value="0" /> <property name="minPoolSize" value="5" /> </bean> <!-- Session Factory Declaration --> <bean id="SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="DataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <!-- Enable the configuration of transactional behavior based on annotations --> <tx:annotation-driven transaction-manager="txManager" /> <!-- Transaction Manager is defined --> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="SessionFactory" /> </bean> </beans>
Code:at net.test.employees.dao.EmployeesDAO.getEmployees(EmployeesDAO.java:27) at net.test.employees.service.EmployeesService.getEmployees(EmployeesService.java:24) 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) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy137.getEmployees(Unknown Source) at net.test.managed.bean.EmployeesManagedBean.getEmpList(EmployeesManagedBean.java:51) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


Reply With Quote
