I've been trying to refactor a java project, moving submodules into separate projects deployed to our internal maven repository (archiva).
The classes from the submodules are the following:
org.example.srv.DomainUser
org.example.srv.DomainUserBean //entity manager
org.example.srv.UserGroup
org.example.srv.UserGroupBean //entity manager
It works fine when the source files are copied into the appropriate package folder inside of the main backend server project, but when we remove the source files from the backend server project and pull the same code in as a maven dependency, I get the following error upon attempting to access the database:
org.hibernate.UnknownEntityTypeException: Unable to locate persister: org.example.srv.DomainUser
Persistence XML for backend server project:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="loginserver">
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
I can only imagine that it is something to do with the bean discovery when the projects are separate, but I'm really perplexed and it would be great to separate these projects with minimal configuration overhead.
Main server project pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example.srv</groupId>
<artifactId>loginserver</artifactId>
<version>0.0.2-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>authobjects</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<finalName>loginserver</finalName>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
</project>
Auth Objects pom.xml (this project also contains ORM code for the classes, including JPQL statement builders, etc.):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<pj.gid>org.example</pj.gid>
<pj.aid>authobjects</pj.aid>
<pj.ver>1.0.2-SNAPSHOT</pj.ver>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<groupId>${pj.gid}</groupId>
<artifactId>${pj.aid}</artifactId>
<version>${pj.ver}</version>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ent.tnp.utils</groupId>
<artifactId>genericentityejb</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav</artifactId>
<version>1.0-beta-2</version>
</extension>
</extensions>
</build>
<distributionManagement>
<repository>
<id>internal</id>
<url>http://archiva.tnp.in/repository/internal/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://archiva.tnp.in/repository/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>internal</id>
<name>Archiva Managed Internal Repository</name>
<url>http://archiva.tnp.in/repository/internal/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<name>Archiva Managed Snapshot Repository</name>
<url>http://archiva.tnp.in/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>internal</id>
<name>Archiva Managed Internal Repository</name>
<url>http://archiva.tnp.in/repository/internal/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<name>Archiva Managed Snapshot Repository</name>
<url>http://archiva.tnp.in/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
Clarification: genericentityejb is an abstract class designed to compose JPQL queries and manage database queries for a JPA entity. The authobjects project extends it once for each of the entities it contains in order to provide persistence for each of those entities.