Unknown entity
hwarang Sep 30, 2010 6:45 AMhey there
I`m using seam 2 with hibernate, ejb3, richfaces, ibm websphere and Rational Software Architect as my IDE (based on eclipse) and I tried to test my persistence entity packages, which are all located in an extra project.
I've created a new project with testng, which just should contain test-classes, who are referencing the entity classes in the persistence project, initiate them and run the tests... but it seems, it's not that easy. I added the imports in the test-classes to the entities in the persistence-project and all seems normal, no errors. I wrote a test, which just initiates the persistence entity, persist it to the oracle db, reads them out trough the entitiy-manager by using "find()" and remove the entity again from the db.
And here comes the error: at the point, where the entitiy-manager tries to persist the entity, I get the following error:
java.lang.IllegalArgumentException: Unknown entity: de.thehive.entity.staticData.Client
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:216)
at de.thehive.entity.staticData.test.ClientTest.testClientPersistence(ClientTest.java:38)
... Removed 22 stack frames
It seems like the application finds the class, otherwise the import wouldn't have worked, but when it tries to persist, it doesn't have the mapping, doesn't have the class in the runtime classpath or whatever. Maybe it's because there is a persistence.xml in the entity-package and an extra persistence.xml in the testng-project?
here's the persistence.xml from the testng-proect. I also tried to publish the class by adding the "<class>"-tag to the xml-file, but it cannot resolve the name? weird..
<?xml version="1.0" encoding="UTF-8"?>
<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="xxx"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- <class>de.thehive.entity.staticData.Client</class> -->
<properties>
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.transaction.manager" value="org.hibernate.transaction.JDBCTransactionFactory" />
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.archive.autodetection" value="class, hbm" />
<!--
Insert your url like jdbc:oracle:thin:@localhost:port:sid
Insert the database username
Insert the database password
-->
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@xxx.de:1521:xx" />
<property name="hibernate.connection.username" value="xxx" />
<property name="hibernate.connection.password" value="xxx" />
</properties>
</persistence-unit>
</persistence>
and the persistence.xml from the entity-project:
<?xml version="1.0" encoding="UTF-8"?>
<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="xxx"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/xxx</jta-data-source>
<mapping-file>org/jbpm/hibernate.wire.hbm.xml</mapping-file>
<mapping-file>org/jbpm/hibernate.definition.hbm.xml</mapping-file>
<mapping-file>org/jbpm/hibernate.queries.hbm.xml</mapping-file>
<mapping-file>org/jbpm/hibernate.execution.hbm.xml</mapping-file>
<mapping-file>org/jbpm/hibernate.type.hbm.xml</mapping-file>
<mapping-file>org/jbpm/hibernate.job.hbm.xml</mapping-file>
<mapping-file>de/thehive/approval/task/approval_process.hbm.xml</mapping-file>
<properties>
<!-- property name="hibernate.hbm2ddl.auto" value="create-drop"/-->
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<!-- <property name="hibernate.default_schema" value="xxx" /> -->
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />
</properties>
</persistence-unit>
</persistence>
any suggestions? ;)
I`m using seam 2 with hibernate, ejb3, richfaces, ibm websphere and Rational Software Architect as my IDE (based on eclipse) and I tried to test my persistence entity packages, which are all located in an extra project.
I've created a new project with testng, which just should contain test-classes, who are referencing the entity classes in the persistence project, initiate them and run the tests... but it seems, it's not that easy. I added the imports in the test-classes to the entities in the persistence-project and all seems normal, no errors. I wrote a test, which just initiates the persistence entity, persist it to the oracle db, reads them out trough the entitiy-manager by using "find()" and remove the entity again from the db.
And here comes the error: at the point, where the entitiy-manager tries to persist the entity, I get the following error:
java.lang.IllegalArgumentException: Unknown entity: de.thehive.entity.staticData.Client
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:216)
at de.thehive.entity.staticData.test.ClientTest.testClientPersistence(ClientTest.java:38)
... Removed 22 stack frames
It seems like the application finds the class, otherwise the import wouldn't have worked, but when it tries to persist, it doesn't have the mapping, doesn't have the class in the runtime classpath or whatever. Maybe it's because there is a persistence.xml in the entity-package and an extra persistence.xml in the testng-project?
here's the persistence.xml from the testng-proect. I also tried to publish the class by adding the "<class>"-tag to the xml-file, but it cannot resolve the name? weird..
<?xml version="1.0" encoding="UTF-8"?>
<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="xxx"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- <class>de.thehive.entity.staticData.Client</class> -->
<properties>
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.transaction.manager" value="org.hibernate.transaction.JDBCTransactionFactory" />
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.archive.autodetection" value="class, hbm" />
<!--
Insert your url like jdbc:oracle:thin:@localhost:port:sid
Insert the database username
Insert the database password
-->
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@xxx.de:1521:xx" />
<property name="hibernate.connection.username" value="xxx" />
<property name="hibernate.connection.password" value="xxx" />
</properties>
</persistence-unit>
</persistence>
and the persistence.xml from the entity-project:
<?xml version="1.0" encoding="UTF-8"?>
<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="xxx"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/xxx</jta-data-source>
<mapping-file>org/jbpm/hibernate.wire.hbm.xml</mapping-file>
<mapping-file>org/jbpm/hibernate.definition.hbm.xml</mapping-file>
<mapping-file>org/jbpm/hibernate.queries.hbm.xml</mapping-file>
<mapping-file>org/jbpm/hibernate.execution.hbm.xml</mapping-file>
<mapping-file>org/jbpm/hibernate.type.hbm.xml</mapping-file>
<mapping-file>org/jbpm/hibernate.job.hbm.xml</mapping-file>
<mapping-file>de/thehive/approval/task/approval_process.hbm.xml</mapping-file>
<properties>
<!-- property name="hibernate.hbm2ddl.auto" value="create-drop"/-->
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<!-- <property name="hibernate.default_schema" value="xxx" /> -->
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />
</properties>
</persistence-unit>
</persistence>
any suggestions? ;)