2 Replies Latest reply: Feb 23, 2012 3:46 AM by Dominik Grupp RSS

    jee:jndi-lookup delivers org.jboss.jca.adapters.jdbc.WrapperDataSource

    Dominik Grupp Newbie

      Hello,

       

      in a MyFaces project on JBoss AS 7 I configured JTA successfully (schema e.g. gets created on the database) via

       

      <jee:jndi-lookup id="entityManagerFactory" jndi-name="java:jboss/datasources/MySqlDS"/>

       

      I am using Spring to configure beans to be injected. One of them

       

      <bean id="persistentContextFactory"
            class="org.apache.myfaces.orchestra.conversation.spring.JpaPersistenceContextFactory">
              <property name="entityManagerFactory" ref="entityManagerFactory"/>
      </bean>

       

      needs the entity manager created earlier. However, the application cannot be deployed because the target bean needs a javax.persistence.EntityManagerFactory but the jndi-lookup delivers org.jboss.jca.adapters.jdbc.WrapperDataSource. See the full error message at the bottom of this posting.

       

      Is there any solution to this?

       

      I tried to search on how to properly integrate spring, hibernate, jta with JBoss and read some posts like
      https://community.jboss.org/message/565183#565183
      https://community.jboss.org/wiki/CombiningESBJPAHibernateJTAAndSpring
      https://community.jboss.org/thread/111654?tstart=0
      https://community.jboss.org/wiki/JBossSpringIntegration

       

      However, they are either not helping me or seem to be outdated. Since I am unsure on whether my config is correct I do attach it here.

       

      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
      version="1.0">
      <persistence-unit name="jatPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>
        <class>de.kdb.domain.User</class>
        <class>de.kdb.domain.Department</class>
        <properties>
         <!-- as defined in org.hibernate.cfg.Environment -->
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
         <property name="hibernate.show_sql" value="true" />
         <property name="hibernate.format_sql" value="true" />
         <property name="hibernate.use_sql_comments" value="true" />
         <property name="hibernate.connection.autocommit" value="false" />
         <property name="hibernate.cache.use_query_cache" value="false" />
         <property name="hibernate.cache.use_second_level_cache" value="false" />
         <property name="hibernate.hbm2ddl.auto" value="create" />
        </properties>
      </persistence-unit>
      </persistence>

       

      spring.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/jee
        http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
      <context:component-scan base-package="de.kdb">
        <context:include-filter type="regex" expression=".service|.dao" />
      </context:component-scan>
      <context:annotation-config />
      <jee:jndi-lookup id="entityManagerFactory" jndi-name="java:jboss/datasources/MySqlDS"/>
      <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
              <property name="transactionManagerName" value="java:/TransactionManager" />
          </bean>
          <tx:annotation-driven transaction-manager="transactionManager" />
      </beans>

       

      web.spring.xml (obviously needs to be separate for conversation scope definition)

       

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:aop="http://www.springframework.org/schema/aop"
             xmlns:context="http://www.springframework.org/schema/context"
             xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/aop
              http://www.springframework.org/schema/aop/spring-aop-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="de.kdb.gui"/>
          <!-- Import Orchestra Spring configuration -->
          <import resource="classpath*:/META-INF/spring-orchestra-init.xml"/>
          <!-- Configure view scope and additional Orchestra scopes -->
          <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
              <property name="scopes">
                  <map>
                      <entry key="view">
                          <bean class="de.kdb.spring.ViewScope"/>
                      </entry>
                      <entry key="manual">
                          <bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
                              <property name="timeout" value="30"/>
                              <property name="advices">
                                  <list>
                                      <ref bean="persistentContextConversationInterceptor"/>
                                  </list>
                              </property>
                          </bean>
                      </entry>
                      <entry key="access">
                          <bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
                              <property name="timeout" value="30"/>
                              <property name="advices">
                                  <list>
                                      <ref bean="persistentContextConversationInterceptor"/>
                                  </list>
                              </property>
                              <property name="lifetime" value="access"/>
                          </bean>
                      </entry>
                      <entry key="viewController">
                          <bean class="org.apache.myfaces.orchestra.viewController.spring.SpringViewControllerScope">
                              <property name="advices">
                                  <list>
                                      <ref bean="persistentContextConversationInterceptor"/>
                                  </list>
                              </property>
                          </bean>
                      </entry>
                  </map>
              </property>
          </bean>
          <!-- Advice to ensure correct persistence context in Orchestra-scoped beans -->
          <bean id="persistentContextConversationInterceptor"
                class="org.apache.myfaces.orchestra.conversation.spring.PersistenceContextConversationInterceptor">
              <property name="persistenceContextFactory" ref="persistentContextFactory"/>
          </bean>
          <!-- Define persistence context factory for JPA -->
          <bean id="persistentContextFactory"
                class="org.apache.myfaces.orchestra.conversation.spring.JpaPersistenceContextFactory">
              <property name="entityManagerFactory" ref="entityManagerFactory"/>
          </bean>
      </beans>

       


      10:15:44,363 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-2) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.factory.config.CustomScopeConfigurer#0' defined in ServletContext resource [/WEB-INF/web.spring.xml]: Cannot create inner bean 'org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope#eb0945' of type [org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope] while setting bean property 'scopes' with key [TypedStringValue: value [manual], target type [null]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope#eb0945' defined in ServletContext resource [/WEB-INF/web.spring.xml]: Cannot resolve reference to bean 'persistentContextConversationInterceptor' while setting bean property 'advices' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistentContextConversationInterceptor' defined in ServletContext resource [/WEB-INF/web.spring.xml]: Cannot resolve reference to bean 'persistentContextFactory' while setting bean property 'persistenceContextFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistentContextFactory' defined in ServletContext resource [/WEB-INF/web.spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.jboss.jca.adapters.jdbc.WrapperDataSource' to required type 'javax.persistence.EntityManagerFactory' for property 'entityManagerFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.jboss.jca.adapters.jdbc.WrapperDataSource] to required type [javax.persistence.EntityManagerFactory] for property 'entityManagerFactory': no matching editors or conversion strategy found
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:281) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:120) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:378) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:161) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1097) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:661) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.10.Final.jar:]
      at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
      at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_26]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_26]
      at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_26]