Announcement Announcement Module
No announcement yet.
JPA Entities from an external JAR: "references an unknown entity" error. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JPA Entities from an external JAR: "references an unknown entity" error.


    We are trying to use an external JAR as a maven dependency containing JPA entities but we have this error:

    Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on ourPackage.OurClass.currency references an unknown entity: ourExternalPackage.Currency
    	at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(
    	at org.hibernate.cfg.Configuration.processEndOfQueue(
    	at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(
    	at org.hibernate.cfg.Configuration.secondPassCompile(
    	at org.hibernate.cfg.Configuration.buildMappings(
    	at org.hibernate.ejb.Ejb3Configuration.buildMappings(
    	at org.hibernate.ejb.EventListenerConfigurator.configure(
    	at org.hibernate.ejb.Ejb3Configuration.configure(
    	at org.hibernate.ejb.Ejb3Configuration.configure(
    	at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(
    	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(
    	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(
    	... 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:


    But not yet the solutions mentioned here: that links to

    However, it doesn't work. This is my persistence.xml.

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <persistence xmlns=""
    	xmlns:xsi="" version="2.0"
    	<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
    			<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="" 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"/>       

    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

    The helper module is finished and the main module only lacks of the details regarding the helper module.

    Thank you very much in advance.

  • #2
    At the end it worked without any intervention from my part.

    Maybe it was a STS problem, because I saw the error the last Friday, but it disappear on Monday.

    To summarize, we have several Roo projects and we want to include into one, that we call the "main project", the rest as maven jar dependencies, we call them the "helper modules". We're trying to build a multi module project building each module as a separate Roo application.

    I don't recommend this approach, because it comes with a lot of manual configuration (error prone) and manual manipulation (in order to avoid conflicts, the best option is to eliminate the XML files from the "helper modules". Besides, the configuration of the application should be done in the application itself, not in the helper modules)

    The process is:
    - For a "helper module": create a complete Roo web project, change the POM packaging to JAR (temporary), remove all the configuration files (application context, persistence and so on) in this JAR.
    - For the "main project": import the "helper modules" as MAVEN dependencies. In the persistence.xml add the entities as individual <class> entries:

    <persistence ...
    	<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
    As far as I know there is no need of configuring autodetection if you're using Hibernate:
    <!-- property name="hibernate.archive.autodetection" value="class, hbm"/ -->
    Now, we need to create the views for the helper entities within the main application.

    Since they're not in the top level package, maybe we'll just copy and paste the Controllers and the view from the helper projects as long as we can use the annotations that they contain. In other case, we will create a Spring MVC objects from scratch.