Announcement Announcement Module
Collapse
No announcement yet.
java.lang.IllegalArgumentException: Unknown entity: xx Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • java.lang.IllegalArgumentException: Unknown entity: xx

    My company have a custom Web application built on Spring 3.0.5.RELEASE, Hibernate Core 3.6.3.Final, Hibernate search 3.4.0.Final, Hibernate validator 4.1.0.Final, Aspectjrt 1.6.2. We had all the integration test running successful with maven and web application working fine.
    I wanted to upgrade the libraries to Spring 3.1.2.RELEASE, Hibernate Core 4.1.6.Final, Hibernate search 4.1.1.Final, Hibernate validator 4.3.0.Final.
    Had to do some changes due to classes deprecation/changes. No changes in the configuration overall. Now when I run the Integration tests I get the following error.

    java.lang.IllegalArgumentException: Unknown entity: xx.model.common.Role
    at org.hibernate.ejb.AbstractEntityManagerImpl.persis t(AbstractEntityManagerImpl.java:868)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.orm.jpa.SharedEntityManagerCre ator$SharedEntityManagerInvocationHandler.invoke(S haredEntityManagerCreator.java:240)
    at $Proxy39.persist(Unknown Source)
    at xx.dao.jpa.GenericJpaDao.persist(GenericJpaDao.jav a:55)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:319)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:183)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :150)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:110)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy41.persist(Unknown Source)
    at xx.model.AbstractPersistentEntity.persist_aroundBo dy20(AbstractPersistentEntity.java:229)
    at xx.model.AbstractPersistentEntity.persist_aroundBo dy21$advice(AbstractPersistentEntity.java:51)
    at xx.model.AbstractPersistentEntity.persist(Abstract PersistentEntity.java:1)
    at xx.model.AbstractPersistentEntity.persist_aroundBo dy10(AbstractPersistentEntity.java:159)
    at xx.model.AbstractPersistentEntity.persist_aroundBo dy11$advice(AbstractPersistentEntity.java:51)
    at xx.model.AbstractPersistentEntity.persist(Abstract PersistentEntity.java:159)
    at xx.util.dataload.AbstractDevDataLoader.persist(Abs tractDevDataLoader.java:88)
    at xx.util.dataload.AbstractDevDataLoader.persist(Abs tractDevDataLoader.java:59)
    at xx.util.dataload.RolePermissionsDevDataLoader.crea teDefaultSystemAdminRole(RolePermissionsDevDataLoa der.java:251)
    at xx.util.dataload.RolePermissionsDevDataLoader.crea teRoles(RolePermissionsDevDataLoader.java:95)
    at xx.util.dataload.RolePermissionsDevDataLoader.doLo adSeedData(RolePermissionsDevDataLoader.java:88)
    at xx.util.dataload.CommonDevDataLoader.doLoadSeedDat a(CommonDevDataLoader.java:94)
    at xx.util.dataload.AbstractDevDataLoader.loadData(Ab stractDevDataLoader.java:40)
    at xx.model.company.CompanyLocationIntTest.onSetUpInT ransaction(CompanyLocationIntTest.java:25)
    at org.springframework.test.AbstractTransactionalSpri ngContextTests.onSetUp(AbstractTransactionalSpring ContextTests.java:203)
    at org.springframework.test.AbstractSingleSpringConte xtTests.setUp(AbstractSingleSpringContextTests.jav a:104)
    at junit.framework.TestCase.runBare(TestCase.java:132 )
    at org.springframework.test.ConditionalTestCase.runBa re(ConditionalTestCase.java:79)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.access$1(AbstractAnnot ationAwareTransactionalTests.java:1)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests$1.run(AbstractAnnotati onAwareTransactionalTests.java:179)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.runTest(AbstractAnnota tionAwareTransactionalTests.java:287)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.runTestTimed(AbstractA nnotationAwareTransactionalTests.java:258)
    at org.springframework.test.annotation.AbstractAnnota tionAwareTransactionalTests.runBare(AbstractAnnota tionAwareTransactionalTests.java:176)
    at org.springframework.test.jpa.AbstractJpaTests.runB are(AbstractJpaTests.java:195)
    at org.springframework.test.jpa.AbstractJpaTests.runB are(AbstractJpaTests.java:276)
    at junit.framework.TestResult$1.protect(TestResult.ja va:110)
    at junit.framework.TestResult.runProtected(TestResult .java:128)
    at junit.framework.TestResult.run(TestResult.java:113 )
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:2 32)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.JUnit38ClassRunner.run( JUnit38ClassRunner.java:83)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)


    I found a lot of google results which says JPA is not auto-registering the objects.

    Synopsis of jpa config:
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="Model" />
    <property name="persistenceXmlLocation" value="classpath:/META-INF/persistence-test.xml" />
    <property name="jpaPropertyMap">
    <map>
    <entry key="hibernate.search.default.directory_provider" value="org.hibernate.search.store.impl.FSDirectory Provider" />
    <entry key="hibernate.search.default.indexBase" value="${fileAttachment.baseDir}/search_indexes" />
    <entry key="hibernate.search.indexing_strategy" value="manual" />
    <entry key="hibernate.search.worker.batch_size" value="50" />
    </map>
    </property>
    <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
    <property name="showSql" value="${jpa.showSql}" />
    <property name="generateDdl" value="${jpa.generateDdl}" />
    <property name="databasePlatform" value="${jpa.databasePlatform}" />
    </bean>
    </property>
    <property name="loadTimeWeaver">
    <bean class="org.springframework.instrument.classloading .InstrumentationLoadTimeWeaver" />
    </property>
    </bean>


    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionM anager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
    <property name="dataSource" ref="dataSource" />
    </bean>

    <aop:aspectj-autoproxy />
    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    <property name="maxActive" value="${jdbc.maxActive}" />
    <property name="initialSize" value="${jdbc.initialSize}" />
    </bean>


    Can anyone help me to get past this error?

  • #2
    Your persistence-test.xml should point to a location where the entities reside. Since Spring 3.1, you can use packagesToScan property on LocalContainerEntityManagerFactoryBean to completely avoid using persistence.xml file since it usually does not contain any important information except entity locations.

    Comment


    • #3
      All my test sources are present in the parent directory (/META_INF) of persistence-test.xml. I suppose in that case, I don't need to specify the class files explicitly.

      Comment


      • #4
        Can someone help me with this issue? I have hit an dead end with this.

        Comment


        • #5
          Relying on default /META_INF subpackage location might not work in some circumstances. For example, in junit tests the packaging can be different than when deployed on an application server. Try to use one of the solutions I have proposed to explicitly configure entity locations. You can try to use PersistenceUnitPostprocessor to see what entities are loaded.
          If nothing works, you can check that all entities are well defined (Serializable, not final). And check that you use JPA 2.0 with Hibernate 4.

          Comment

          Working...
          X