Announcement Announcement Module
Collapse
No announcement yet.
Problem using Hibernate Support and JSF Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem using Hibernate Support and JSF

    I have an application usig JSF + Spring. At the start I was using hard-coded DAO objects to access EIS layer. Then i decided to move to Hibernate, using Spring's templates. The fact is that when i use Hibernate, the application does not work, there's an error which causes my backing beans in the presentation layer fail. I have made some debuging, and came to the conclusion that this line (present in all backing beans) is the one causing troubles.

    appContext = WebApplicationContextUtils.getRequiredWebApplicati onContext(context);

    The application context xml file is:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>	 
    	
    <!-- DataSource Definition -->
    <bean id="mydataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName">
    <value>oracle.jdbc.driver.OracleDriver</value>
    </property>
    <property name="url">
    <value>jdbc&#58;oracle&#58;thin&#58;@127.0.0.1&#58;1521&#58;LICAPALC</value>
    </property>
    <property name="username">
    <value>adminlicapa</value>
    </property>
    <property name="password">
    <value>adaptacion</value>
    </property>
    </bean>
    	
    <!-- Spring Data Access Exception Translator Defintion -->
    <bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator"> 
    
    <property name="dataSource"><ref bean="mydataSource"/></property> 
    </bean> 
    	
    <!--Definicion del DAO de categoria-->
    <bean id="categoriaDao" class="co.edu.unal.licapa.model.dao.hibernate.CategoriaDaoHibernateImpl">
    <property name="hibernateTemplate"><ref bean="hibernateTemplate"/></property> 
    </bean>
    <!-- Administracion de Capacitacion Virtual Service Defintion -->
    
    <bean id="administracionVirtualService" class="co.edu.unal.licapa.model.service.impl.ServiceAdministracionVirtualImpl">
    <property name="categoriaDao"><ref local="categoriaDao"/></property>
    </bean>
    	
    <!-- Hibernate Template Defintion -->
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate.HibernateTemplate"> 
    <property name="sessionFactory"><ref bean="sessionFactory"/></property> 
    <property name="jdbcExceptionTranslator"><ref bean="jdbcExceptionTranslator"/></property> 
    </bean> 
    
    
    <!-- Hibernate SessionFactory Definition -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
    <property name="mappingResources">
    <list>
    <value>co/edu/unal/licapa/model/bo/Categoria.hbm.xml</value>	
    </list>
    </property>		
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
    <prop key="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</prop>
    </props>
    </property>	
    		
    <property name="dataSource">
    <ref bean="mydataSource"/>
    </property>
    </bean>
    	
    	
    </beans>
    Notice that the application works well with the next context:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC  "-//SPRING//DTD BEAN//EN"  "http&#58;//www.springframework.org/dtd/ spring-beans.dtd">
    
    <beans>	 
    <!-- DataSource Definition -->
    
    <bean id="mydataSource" class="org.apache.commons.dbcp.Basic
    DataSource" destroy-method="close">
    <property  name="driverClassName">
    <value>oracle.jdbc.driver.OracleDriver</value>
    </property>
    
    <property name="url">
    <value>jdbc&#58;oracle&#58;thin&#58;@127.0.0.1&#58;1521&#58;LICAPALC</value>
    </property>
    
    <property name="username">
    <value>adminlicapa</value>
    </property>
    
    <property  name="password">
    <value>adaptacion</value>
    </property>
    </bean>
    	
    <!-- Spring Data Access  Exception Translator Defintion -->
    <bean  id="jdbcExceptionTranslator" 
    class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator"> 
    <property name="dataSource"><ref bean="mydataSource"/></property> 
    </bean> 
    
    <!--Definicion del DAO de categoria-->
    	
    <bean id="categoriaDao" 
    class="co.edu.unal.licapa.model.dao.jdbc.CategoriaDaoJdbcImpl2">
    <property name="dataSource"><ref 
    bean="mydataSource"/></property> 
    </bean>
    
    <!-- Administracion de Capacitacion Virtual Service Defintion -->
    
    <bean id="administracionVirtualService" 
    class="co.edu.unal.licapa.model.service.impl.ServiceAdministracionVirtua
    lImpl">
    
    <property name="categoriaDao"><ref 
    local="categoriaDao"/>
    </property>
    </bean>
    	
    
    	
    	
    </beans>
    Any Ideas? I'm in a hurry, plz help! :?:

    Julian

  • #2
    Forgot to say that appContext.xml is valid, and all the beans exist. I am using Spring-IDE with eclipse, no errors are reported.

    Comment


    • #3
      It's hard to even begin to try to help you since you don't really describe what you mean when you say the application doesn't work, and your backing beans in the presentation layer fail.

      Are you getting an exception, can you provide a stack trace, etc?

      Comment


      • #4
        The error is :
        2004-09-22 15:18:55 ApplicationDispatcher[/capacitacion104] El Servlet.service() para servlet Faces Servlet lanzó una excepción
        javax.faces.el.PropertyNotFoundException: Can't instantiate class: 'Can't get value from value reference expression: '#{serviceLocatorBean}'.'.
        at com.sun.faces.application.ApplicationImpl.createAn dMaybeStoreManagedBeans(ApplicationImpl.java:872)
        at com.sun.faces.el.VariableResolverImpl.resolveVaria ble(VariableResolverImpl.java:79)
        at com.sun.faces.el.impl.NamedValue.evaluate(NamedVal ue.java:120)
        at com.sun.faces.el.impl.ComplexValue.evaluate(Comple xValue.java:141)
        at com.sun.faces.el.impl.ExpressionEvaluatorImpl.eval uate(ExpressionEvaluatorImpl.java:238)
        at com.sun.faces.el.ValueBindingImpl.getValue(ValueBi ndingImpl.java:155)
        at com.sun.faces.el.ValueBindingImpl.getValue(ValueBi ndingImpl.java:136)
        at javax.faces.component.UIOutput.getValue(UIOutput.j ava:147)
        at com.sun.faces.renderkit.html_basic.HtmlBasicInputR enderer.getValue(HtmlBasicInputRenderer.java:81)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRender er.getCurrentValue(HtmlBasicRenderer.java:192)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRender er.encodeEnd(HtmlBasicRenderer.java:170)
        at javax.faces.component.UIComponentBase.encodeEnd(UI ComponentBase.java:713)
        at javax.faces.webapp.UIComponentTag.encodeEnd(UIComp onentTag.java:606)
        at javax.faces.webapp.UIComponentTag.doEndTag(UICompo nentTag.java:529)
        at com.sun.faces.taglib.html_basic.InputTextTag.doEnd Tag(InputTextTag.java:518)
        at org.apache.jsp.crearCategoria_jsp._jspx_meth_h_inp utText_0(crearCategoria_jsp.java:220)
        at org.apache.jsp.crearCategoria_jsp._jspx_meth_h_for m_0(crearCategoria_jsp.java:154)
        at org.apache.jsp.crearCategoria_jsp._jspx_meth_f_vie w_0(crearCategoria_jsp.java:115)
        at org.apache.jsp.crearCategoria_jsp._jspService(crea rCategoria_jsp.java:77)
        at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:94)
        at javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
        at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:298)
        at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
        at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
        at javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
        at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:237)
        at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:157)
        at org.apache.catalina.core.ApplicationDispatcher.inv oke(ApplicationDispatcher.java:703)
        at org.apache.catalina.core.ApplicationDispatcher.pro cessRequest(ApplicationDispatcher.java:463)
        at org.apache.catalina.core.ApplicationDispatcher.doF orward(ApplicationDispatcher.java:398)
        at org.apache.catalina.core.ApplicationDispatcher.for ward(ApplicationDispatcher.java:312)
        at com.sun.faces.context.ExternalContextImpl.dispatch (ExternalContextImpl.java:322)
        at com.sun.faces.application.ViewHandlerImpl.renderVi ew(ViewHandlerImpl.java:142)
        at com.sun.faces.lifecycle.RenderResponsePhase.execut e(RenderResponsePhase.java:87)
        at com.sun.faces.lifecycle.LifecycleImpl.phase(Lifecy cleImpl.java:200)
        at com.sun.faces.lifecycle.LifecycleImpl.render(Lifec ycleImpl.java:117)
        at javax.faces.webapp.FacesServlet.service(FacesServl et.java:198)
        at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:237)
        at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:157)
        at org.apache.catalina.core.ApplicationDispatcher.inv oke(ApplicationDispatcher.java:703)
        at org.apache.catalina.core.ApplicationDispatcher.pro cessRequest(ApplicationDispatcher.java:463)
        at org.apache.catalina.core.ApplicationDispatcher.doF orward(ApplicationDispatcher.java:398)
        at org.apache.catalina.core.ApplicationDispatcher.for ward(ApplicationDispatcher.java:312)
        at org.apache.jasper.runtime.PageContextImpl.doForwar d(PageContextImpl.java:670)
        at org.apache.jasper.runtime.PageContextImpl.forward( PageContextImpl.java:637)
        at org.apache.jsp.index_jsp._jspService(index_jsp.jav a:52)
        at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:94)
        at javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
        at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:298)
        at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
        at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
        at javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
        at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:237)
        at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:157)
        at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:214)
        at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
        at org.apache.catalina.core.StandardContextValve.invo keInternal(StandardContextValve.java:198)
        at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:152)
        at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
        at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:137)
        at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
        at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:117)
        at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:102)
        at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
        at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
        at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
        at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:929)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(Co yoteAdapter.java:160)
        at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:793)
        at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:702)
        at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:571)
        at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:644)
        at java.lang.Thread.run(Thread.java:534)
        Notice that serviceLocatorBean is a property common for all my backing beans in the view layer. It has an appContext property, corresponding to the Spring Context.[/code]

        Comment


        • #5
          Since it's blowing up inside of the JSF specific code it's hard to tell what's going wrong unfortunately. Is there a chance some exception (at the data access layer) is getting swallowed?

          What I would probably do in this situation is start tracing, and validate that all the objects are where they are supposed to be. I.e. if the Faces code is trying to access stuff, you can try accessing the same stuff via the debugger, when you get to a breakpoint...

          Comment


          • #6
            Note that some versions of Sun's JSF RI have a bug in that they don't invoke a custom VariableResolver for expressions in property values of JSF-managed beans. Therefore, Spring's DelegatingVariableResolver does kick in properly there - which is not its own fault, though.

            I've been told that the very latest JSF RI fixes this issue; however, I haven't tested this myself. All MyFaces version that I've tested work properly, though. Please check the latest RI version or MyFaces, and let me know whether this fixes your issue!

            Juergen

            Comment


            • #7
              I am not sure I can use my-faces implementation, but just in case I will give it a try...the fact is that the variable is properly resolved when I use the appContext.xml file specified above, without hibernate support. This may implie that the actual problem occurs in my middle tier, where I use Spring framework.

              Comment


              • #8
                Are you sure the AppContext is even properly loaded (i.e. there is a failure in the initial load or subsequent creation of some lazy loaded or prototype beans).

                Comment


                • #9
                  I have made some debugging, fact is, when I use the appContext.xml that fails (see above), the programme actually never goes through these lines:
                  Code:
                  ServletContext context = &#40;ServletContext&#41;FacesContext.getCurrentInstance&#40;&#41;.getExternalContext&#40;&#41;.getContext&#40;&#41;;
                  		
                  this.appContext = WebApplicationContextUtils.getRequiredWebApplicationContext&#40;context&#41;;
                  which I use in a servivelocator bean to invoke all of my bussines services.

                  When i use the other appContext.mxl, without hibernate templates and sessions (see above), the application works and go through the lines, as it is supposed to be. I'm not changing anything else than the appContext.xml, so I guess the problem lies in Spring's core.

                  Any Ideas?

                  Comment


                  • #10
                    This is the exact same thread as here:

                    http://forum.springframework.org/showthread.php?t=10464
                    (this link was originally wrong, now corrected!)

                    Anybody wanting to reply, please use the other thread from now on.

                    And everybody posting new topics, please do not double post...
                    Last edited by robyn; May 14th, 2006, 10:07 AM.

                    Comment

                    Working...
                    X