Is it possible to scan Entities in jar files using JPA and hibernate

Posted by user1260109 on Stack Overflow See other posts from Stack Overflow or by user1260109
Published on 2012-03-22T22:07:35Z Indexed on 2012/03/23 11:30 UTC
Read the original article Hit count: 312

Filed under:
|
|

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>

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about jpa