IllegalArgumentException:不是托管类型

时间:2016-02-15 12:45:12

标签: spring hibernate spring-data hibernate-mapping hibernate-ogm

我正在使用Spring Data with Hibernate和mongo db。我在尝试将我的webapp部署到Wildfly 10时遇到了以下堆栈。

  

引起:java.lang.IllegalArgumentException:不是托管类型:   class class com.olp.jpa.domain.docu.product.ProductTemplateBean at   org.hibernate.jpa.internal.metamodel.MetamodelImpl.managedType(MetamodelImpl.java:219)     在   org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation。(JpaMetamodelEntityInformation.java:68)     在   org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getMetadata(JpaEntityInformationSupport.java:65)     在   org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:149)     在   org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:88)     在   org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:68)     在   org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:159)     在   org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224)     在   org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210)     在   org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)     ......还有35个

使用SpringJUnit4ClassRunner在Junit中测试时,代码运行正常。仅在Wildfly部署期间,我收到此错误。以下各种文物的片段:

  1. 的web.xml

    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd“>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
    </context-param>
    
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    

  2. Spring config

    http://www.springframework.org/schema/beans/spring-beans.xsd           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd           http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd           http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd

      

    <context:component-scan base-package="com.olp"/>
    
    <tx:annotation-driven />
    
    <jpa:repositories base-package="com.olp.jpa.domain"  entity-manager-factory-ref="entityManagerFactory"/>
    
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
      <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitManager" ref="persistenceUnitMgr"/>
        <property name="jpaDialect" ref="jpaDialect"/>
        <property name="jpaVendorAdapter" ref="ogmVendorAdapter"/>
    </bean>
    
    <bean id="persistenceUnitMgr" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
        <property name="persistenceUnitPostProcessors">
            <array>
                <ref bean="persistencePostProcessor"/>
            </array>
        </property>
        <property name="persistenceXmlLocation" value="classpath:META-INF/persistence_olp.xml"/>
        <property name="defaultPersistenceUnitName" value="productHub"/>
        <property name="packagesToScan" value="com.olp.jpa.domain.docu" />
    </bean>
    
    <bean id="persistencePostProcessor" class="com.olp.jpa.OlpPersistenceUnitPostProcessor"/>
    
    <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
    
    <bean id="ogmVendorAdapter" class="com.olp.jpa.OlpHibernateOgmVendorAdapter"/>
    

  3. JPA conf(persistence_olp.xml)

    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">        org.hibernate.ogm.jpa.HibernateOgmPersistence     ENABLE_SELECTIVE

        <properties>
    
            <!--
                All other hibernate / mongo properties are externalized and provided by persistence unit post-processor in Spring
            -->
    
            <property name="jboss.as.jpa.managed" value="false" />
    
        </properties>
    

  4. 实体抛出异常(ProductTemplateBean.java)

    package com.olp.jpa.domain.docu.product;

    @Entity @table(名称= “phub_product_template”) 公共类ProductTemplateBean实现Serializable {

    @Id
    @DocumentId
    @GeneratedValue(strategy = GenerationType.AUTO)
    //@Type(type = "objectid")
    private Long id;
    
    // Omitting other fields & getters setters for brevity
    

    }

  5. Wildfly类加载器conf(jboss-deployment-structure.xml)

        

        <exclusions>
            <module name="org.hibernate"/>
            <module name="org.hibernate.search.orm"/>
            <module name="org.hibernate.search.engine"/>
            <module name="org.hibernate.validator"/>
            <module name="org.codehaus"/>
            <module name="resteasy" />
        </exclusions>
    
    </deployment>
    

  6. 如果有人能提出一些指示,我真的很感激。我已经阅读了一些相关文章,其中大部分都指向“packagesToScan”属性。这已经正确配置。

    打破我的头很长一段时间!提前感谢您提供任何帮助。

0 个答案:

没有答案