2

I have the following situation :

  • Project A - Contains a few entities and is independent
  • Project B - Contains a few entities and is independent
  • Project C - Contains few entities and is dependent on Project A & Project B.

I am using Maven to manage dependencies and builds.

When I try to test Project A and project B it goes through fine. Each of them has a persistence.xml and a separate persistent context.

When I run Project C , It does map any of the entities. I have tried to use the auto-detect, specified the jar file attribute ... but nothing seems to work.

It gives me a Mapping Exception saying unknown entity and wont persist or read the Entities from Projects A or B. I have posted the 3 persistence.xml files here.

Also, I tried using the class attribute and using the same persistent context but it just wont find the files.

Any help is really appreciated.

Thanks in advance !

<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="A" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
    <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.connection.username" value="username"/>
      <property name="hibernate.connection.password" value="password"/>
      <property name="hibernate.connection.url" value="jdbc:oracle:thin:@webdev.epi.web:1521/webdev.world"/>
      <property name="hibernate.max_fetch_depth" value="3"/>
      <property name="hibernate.archive.autodetection" value="class"/>
    </properties>

        </persistence-unit>
</persistence>

<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="B" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
    <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.connection.username" value="username"/>
      <property name="hibernate.connection.password" value="password"/>
      <property name="hibernate.connection.url" value="jdbc:oracle:thin:@webdev.epi.web:1521/webdev.world"/>
      <property name="hibernate.max_fetch_depth" value="3"/>
      <property name="hibernate.archive.autodetection" value="class"/>
    </properties>

        </persistence-unit>
</persistence>

<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="C" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jar-file>A-0.0.1-SNAPSHOT.jar</jar-file>
                    <jar-file>B-0.0.1-SNAPSHOT.jar</jar-file>
        <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
    <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.connection.username" value="username"/>
      <property name="hibernate.connection.password" value="password"/>
      <property name="hibernate.connection.url" value="jdbc:oracle:thin:@webdev.epi.web:1521/webdev.world"/>
      <property name="hibernate.max_fetch_depth" value="3"/>
      <property name="hibernate.archive.autodetection" value="class"/>
    </properties>

        </persistence-unit>
</persistence>

2 Answers 2

1

Actually, I found a way to make it work. In Projects A & B , I autodetect my entities and in Project C , I explicitly list the mapped classes, the entities are now getting mapped and it works.

Hope it helps some one else !

0

To enable auto-detection in your project C as well, you can scan the classpath yourself and register the JPA entities to Hibernate programatically. There is thus no need to explicitly list those entities in persistence.xml. For more information see here: https://stackoverflow.com/a/41845759/377320

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.