Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Problem using Hibernate Support and JSF

  1. #1

    Default 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 Garcia.

  2. #2

    Default

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

  3. #3
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    Julian,

    You have neglected to mention what the actual error is .

    Can you provide us with some more details as to what error is actually occuring?

    Rob

  4. #4

    Default

    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.
    Julian Garcia.

  5. #5

    Default

    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?
    Julian Garcia.

  6. #6
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    Julian,

    I am a bit stumped with this one - the error message you have posted seems to have nothing to with Spring - there are no Spring classes mentioned in the stack trace. However, I am not familiar with the JSF stuff so I have posted this on the developer list to see what everyone thinks.

    Rob

  7. #7
    Join Date
    Aug 2004
    Posts
    1,067

    Default

    My guess is that the exception shown in the stack trace is the result of another exception being thrown when the application context is being loaded. In short, I predict that the app context isn't getting loaded correctly.

    What could be cause this? Well, the most likely culprit is a classpath issue. If Spring is trying to instantiate a bean, but can't find something that the bean depends on, it will fail and throw a BeanCreationException. Perhaps this is getting swallowed and the PropertyNotFoundException is being thrown in its place. Do you have all of the dependency JARs in your app's classpath?

    I mocked up your CategoriaDaoHibernateImpl and ServiceAdministracionVirtualImpl classes and tried to load your troubled application context. In order to get it to load I had to include the following JARs:

    - spring.jar
    - commons-logging.jar
    - commons-dbcp.jar
    - commons-pool.jar
    - hibernate2.jar
    - jta.jar
    - dom4j.jar
    - cglib-full-2.0.2.jar
    - commons-collections.jar
    - The Oracle JDBC driver JAR

    Are all of these in your app's classpath?

  8. #8
    Join Date
    Aug 2004
    Posts
    1,067

    Default

    More info: With the other context (the one that works for you), I needed the following JARS:

    - spring.jar
    - commons-logging.jar
    - commons-dbcp.jar
    - commons-pool.jar
    - commons-collections.jar
    - Oracle JDBC driver JAR

    The difference between these dependencies and the previous set of dependency JARs may point to your problem:

    - hibernate2.jar
    - jta.jar
    - dom4j.jar
    - cglib-full-2.0.2.jar

    If your app's classpath is missing any of these, then you certainly won't be able to load the application context.

    Of course, that's not to say that there aren't more dependencies that come into play once your app gets started...but just to load the context you'll need the set of dependencies in my last post.

  9. #9
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    The exception looks like the one I originally encountered as bug in Sun's JSF RI: It simply doesn't ask a custom VariableResolver for variable names in JSF-managed bean properties. If Spring's DelegatingVariableResolver got asked, it would find the bean in the Spring context, but it doesn't even get asked...

    The above works nicely with MyFaces, and reportedly also with the newest version of the Sun RI. So if I'm not missing your point with the above, it might be worth updating to the latest RI or trying a different JSF implementation.

    Juergen

  10. #10

    Default

    Regarding the classpath, everything is ok. ServiceLocatorBean, the class that loads the appContext, is not managed through Spring, but using JSF manged-beans since it is a class in the view layer (I use Spring for the bussines layer). Fact is that the constructor of such class seems not to be invoked when using the appContext.xml that fails. Notice that the constructor is properly invoked when using the appContext with no Hibernate support.
    Julian Garcia.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •