Announcement Announcement Module
Collapse
No announcement yet.
Getting nullpointer exception when Annotation are used for Spring 3 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting nullpointer exception when Annotation are used for Spring 3

    Hello

    I have a small application using Spring 3 and Hibernate 4 with JSF2, When I am running the application I am getting.

    Code:
      java.lang.NullPointerException at
        net.test.managed.bean.EmployeesManagedBean.getEmpList(EmployeesManagedBean.java:53)
    What am I doing wrongly to get **nullpointer exception**? Any help is highly appreciable.

    Thanks

    ManagedBean:


    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;
            }
        }
    and I have Inject annotation:


    In EmployeesService 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();
        }
    In EmployeesDAO I have annotations like:

    Code:
        @Named
        public class EmployeesDAO implements IEmployeesDAO {
       
    
        @Override
        public List<Employees> getEmployees() {
            List query = this.getSessionFactory().getCurrentSession().getNamedQuery("getEmp").list();                
            return query;
        }
    Entity class:

    Code:
        @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 {
    and finally in applicationContext.xml I have

    Code:
    <context:component-scan base-package="net.test" />

    applicationContext.xml:

    Code:
        <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>
    Stacktrace
    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)
    Last edited by pol; Dec 10th, 2012, 06:02 AM.

  • #2
    Please post the FULL stacktrace (why do people always post snippets the most interesting stuff is in general at the bottom of the stacktrace).

    Judging from your annotations and the stacktrace is that you are trying to mix CDI and spring and expect CDI to inject spring managed beans. That isn't going to happen, also if your EmployeesManagedBean is a JSF managed bean make sure you configure the appropriate SpringBeansELResolver else it wont work.'

    Also why are you adding all elements to another list instead of reeturning the list from the dao? In case of exception return empty list. Adding all these elements to a new list is just overhead.

    Comment


    • #3
      Thanks for your reply, very much appreciated.

      Originally posted by Marten Deinum View Post
      Please post the FULL stacktrace (why do people always post snippets the most interesting stuff is in general at the bottom of the stacktrace).
      I have added full stacktrace.

      Judging from your annotations and the stacktrace is that you are trying to mix CDI and spring and expect CDI to inject spring managed beans. That isn't going to happen, also if your EmployeesManagedBean is a JSF managed bean make sure you configure the appropriate SpringBeansELResolver else it wont work.'
      If I do not want to use CDI, I would prefer to use Spring, what changes I need to make? And where should I add SpringBeansELResolver? In faces-config.xml?

      Also why are you adding all elements to another list instead of reeturning the list from the dao? In case of exception return empty list. Adding all these elements to a new list is just overhead.
      Could you more specific in this?

      Comment


      • #4
        For some reason the stacktrace seems to short there must be something more it seems cut of halfway through.

        However this stacktrace at least tells that you aren't using/mixing CDI and Spring so you can ignore that comment. For starters I would remove the getters for the dao/service/sessionfactory (IDE should remove the feature to generate getters/setters). Those fields are local to the class so simply use them directly instead of adding the get* method.

        If you want to intergate JSF and Spring you need the SpringBeanFacesELResolver in your faces-config but I guess you already have this in place (else you wouldn't hit this bean anyway).

        Regarding the list in your JSF bean you are constructing an empty list, execute query, add all results to the initial empty list. Why... This is only adding memory and degrades performance while it adds nothing. Simply return the list from the dao directly (if nothing matches you get an empty list anyway). Simply return an empty list in case of an exception (not sure what can go wrong with it but alas, I would probably depend on the general exception handling mechanism and show a nice error page instead of no result).

        Comment


        • #5
          This is my full error stacktrace, I am still not able to figure out the problem.

          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)
          	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 javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
          	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
          	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
          	at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
          	at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
          	at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
          	at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
          	at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
          	at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
          	at javax.faces.component.UIData.getValue(UIData.java:731)
          	at org.primefaces.component.datatable.DataTable.getValue(DataTable.java:729)
          	at org.primefaces.component.api.UIData.getDataModel(UIData.java:581)
          	at javax.faces.component.UIData.isRowAvailable(UIData.java:343)
          	at org.primefaces.component.api.UIData.setRowModel(UIData.java:424)
          	at org.primefaces.component.api.UIData.setRowIndex(UIData.java:403)
          	at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:633)
          	at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:220)
          	at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:192)
          	at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:74)
          	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
          	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763)
          	at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
          	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
          	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
          	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
          	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
          	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
          	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
          	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
          	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
          	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
          	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
          	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
          	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
          	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
          	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
          	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
          	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
          	at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
          	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
          	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
          	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
          	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
          	at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
          	at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
          	at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
          	at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
          	at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
          	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
          	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
          	at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
          	at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
          	at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
          	at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
          	at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
          	at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
          	at java.lang.Thread.run(Thread.java:662)

          Comment


          • #6
            Apparently your dao is wrong. My guess is you forgot an annotation on the SessionoFactory in your dao.

            Comment


            • #7
              Thanks again, could you point out what am I missing in DAO?

              Here is the complete code of DAO

              Code:
              @Named
              public class EmployeesDAO implements IEmployeesDAO {
              
              	private SessionFactory sessionFactory;	
              
              	@Override
              	public List<Employees> getEmployees() {
              		
              		List query = new ArrayList<Employees>();
              		 try{
              		 query = this.getSessionFactory().getCurrentSession()
              				.getNamedQuery("getEmp").list();
              		 }
              		 catch(Exception e){
              			 System.out.println("exception "+e.getMessage());
              			 e.printStackTrace();
              		 }
              		return query;
              	}
              
              	public SessionFactory getSessionFactory() {
              		return sessionFactory;
              	}
              
              	public void setSessionFactory(SessionFactory sessionFactory) {
              		this.sessionFactory = sessionFactory;
              	}
              
              }

              Comment


              • #8
                Thanks again, could you point out what am I missing in DAO?
                Read my previous post!

                Originally posted by mdeinum
                you forgot an annotation on the SessionoFactory in your dao
                How does spring know it needs to inject the SessionFactory? There is no @Inject/@Autowired or the like on the field or setter.

                And please remove the getter (and seter if you put @Inject on the field) use the field directly instead of the getter.

                Comment


                • #9
                  I have modified my DAO as


                  Code:
                  @Named
                  public class EmployeesDAO implements IEmployeesDAO {
                  
                  	@Inject
                  	private SessionFactory sessionFactory;
                  	
                  	@Override
                  	public List<Employees> getEmployees() {
                  		
                  		List query = new ArrayList<Employees>();
                  		 try{
                  		 query = sessionFactory.getCurrentSession()
                  				.getNamedQuery("getEmp").list();
                  		 }
                  		 catch(Exception e){
                  			 System.out.println("exception "+e.getMessage());
                  			 e.printStackTrace();
                  		 }
                  		return query;
                  	}
                  
                  
                  }
                  Null pointer exception is resolved, now I am getting the foillowing exception

                  Code:
                  exception Named query not known: getEmp
                  SEVERE: org.hibernate.MappingException: Named query not knownz: getEmp
                  	at org.hibernate.internal.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:149)
                  	at org.hibernate.internal.SessionImpl.getNamedQuery(SessionImpl.java:1257)
                  	at net.test.employees.dao.EmployeesDAO.getEmployees(EmployeesDAO.java:34)
                  	at net.test.employees.service.EmployeesService.getEmployees(EmployeesService.java:24)
                  	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                  	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                  	at java.lang.reflect.Method.invoke(Method.java:601)
                  	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 $Proxy141.getEmployees(Unknown Source)
                  	at net.test.managed.bean.EmployeesManagedBean.getEmpList(EmployeesManagedBean.java:50)
                  	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                  	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                  	at java.lang.reflect.Method.invoke(Method.java:601)
                  	at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
                  	at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
                  	at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
                  	at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
                  	at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
                  	at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
                  	at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
                  	at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
                  	at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
                  	at javax.faces.component.UIData.getValue(UIData.java:554)
                  	at org.primefaces.component.datatable.DataTable.getValue(DataTable.java:729)
                  	at org.primefaces.component.api.UIData.getDataModel(UIData.java:581)
                  	at javax.faces.component.UIData.isRowAvailable(UIData.java:326)
                  	at org.primefaces.component.api.UIData.setRowModel(UIData.java:424)
                  	at org.primefaces.component.api.UIData.setRowIndex(UIData.java:403)
                  	at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:633)
                  	at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:220)
                  	at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:192)
                  	at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:74)
                  	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
                  	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620)
                  	at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
                  	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
                  	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
                  	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
                  	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
                  	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
                  	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
                  	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
                  	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
                  	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                  	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
                  	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
                  	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
                  	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:325)
                  	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
                  	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:722)

                  Comment


                  • #10
                    You haven't specified packages to scan on the LocalSessionFactoryBean so no entities will be detected.

                    Comment


                    • #11
                      I have specified to scan all Entity and DAO classes in applicationContext.xml

                      Code:
                      <context:component-scan base-package="net.bapco" />

                      Comment


                      • #12
                        I strongly suggest a read of the reference guide (especially on what component-scan does and doesn't do) and rereading my post.

                        Originally posted by mdeinum
                        You haven't specified packages to scan on the LocalSessionFactoryBean
                        In short component-scan doesn't do anything for @Entities that is the responsiblitiy of the SessionFactory (and as such it needs to be configured).

                        Comment


                        • #13
                          Thanks for pointing that out. I have added the following
                          Code:
                          <bean id="SessionFactory"
                          		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
                          		<property name="dataSource" ref="DataSource" />
                          		 <property name="annotatedClasses">	
                          		  <list>
                                     <value>net.test.model.Employees</value>
                                     </list>	
                                     </property>
                          and that problem got resolved. Now next issue is

                          Code:
                          SEVERE: org.hibernate.exception.GenericJDBCException: Missing IN or OUT parameter at index:: 1

                          Comment


                          • #14
                            I have resolved all my errors. Thanks a lot for your help and kindness. Very much appreciated.

                            I have one doubt though. If component-scan doesn't do anything for @Entities, then do we need to define all Entity classes in applicationContext.xml? Is this the best practice or are there better approaches to this?

                            Thanks again.

                            Comment

                            Working...
                            X