JPA Entities from an external JAR: "references an unknown entity" error.
Hello,
We are trying to use an external JAR as a maven dependency containing JPA entities but we have this error:
Code:
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on ourPackage.OurClass.currency references an unknown entity: ourExternalPackage.Currency
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:107)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1550)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1473)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1389)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1477)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1096)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:685)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 47 more
Can anybody help us with this problem?
Some context below:
We'd like to use a multi module project. Instead of that, half of the team has been working in the main module, a Roo web application, and the other half has created a helper module as a Roo web application, but at the end only a Maven JAR is created in order to include it as a Maven dependency in the main project.
Afterwards, we will create the appropriate modules for an EAR project to be deployed in a WebSphere Application Server.
However, the main Roo web project doesn't recognize the Entities within the external JAR, included as a Maven dependecy, as you can see in the error above.
After a long Google search, I tried something like:
http://stackoverflow.com/questions/1...ersistence-xml
or
http://stackoverflow.com/questions/2...se-environment
But not yet the solutions mentioned here:
http://forum.springsource.org/showth...lt-jar-file-gt that links to http://javathoughts.capesugarbird.co...nce-units.html
However, it doesn't work. This is my persistence.xml.
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>ourExternalPackage.Currency</class>
<class>ourExternalPackage.AnotherClass</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2390Dialect"/>
<!-- value="create" to build a new database on each run; value="update"
to modify an existing database; value="create-drop" means the same as "create"
but also drops tables when Hibernate closes; value="validate" makes no changes
to the database -->
<!-- property name="hibernate.hbm2ddl.auto" value="validate" /-->
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<property name="hibernate.connection.charSet" value="UTF-8" />
<!-- Uncomment the following two properties for JBoss only -->
<!-- property name="hibernate.validator.apply_to_ddl" value="false" / -->
<!-- property name="hibernate.validator.autoregister_listeners" value="false" / -->
<!-- property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/-->
<property name="hibernate.archive.autodetection" value="class, hbm"/>
</properties>
</persistence-unit>
</persistence>
The helper project works correctly (build success in its test integration), so, there is no error in the annotations (@Entity is the one from JPA, not the Hibernate, and the Entity is not missing, actually it is in the JAR, as it seems to occur here http://forum.springsource.org/showth...rnate-mappings)
The helper module is finished and the main module only lacks of the details regarding the helper module.
Thank you very much in advance.