--- /dev/null
+<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>de.juplo</groupId>
+ <artifactId>multiple-persistence-units</artifactId>
+ <name>Hibernate 4 Dependency-Test</name>
+ <version>1.0-SNAPSHOT</version>
+
+ <properties>
+ <hibernate-maven-plugin.version>@project.version@</hibernate-maven-plugin.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.hibernate.javax.persistence</groupId>
+ <artifactId>hibernate-jpa-2.1-api</artifactId>
+ <version>1.0.0.Final</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.3</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ <encoding>utf8</encoding>
+ <showWarnings>true</showWarnings>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>de.juplo</groupId>
+ <artifactId>hibernate-maven-plugin</artifactId>
+ <version>${hibernate-maven-plugin.version}</version>
+ <executions>
+ <execution>
+ <id>Create A</id>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ <configuration>
+ <persistenceUnit>A</persistenceUnit>
+ <outputFile>a-create.sql</outputFile>
+ </configuration>
+ </execution>
+ <execution>
+ <id>Drop B</id>
+ <goals>
+ <goal>drop</goal>
+ </goals>
+ <configuration>
+ <persistenceUnit>B</persistenceUnit>
+ <outputFile>b-drop.sql</outputFile>
+ </configuration>
+ </execution>
+ <execution>
+ <id>Create B</id>
+ <goals>
+ <goal>create</goal>
+ </goals>
+ <configuration>
+ <persistenceUnit>B</persistenceUnit>
+ <outputFile>b-create.sql</outputFile>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <export>false</export>
+ <format>true</format>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
--- /dev/null
+package a;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+
+public class Employee {
+ private int empId;
+ private String empName;
+ private double empSalary;
+ public Employee() {
+ }
+ public Employee(int empId, String empName, double empSalary) {
+ this.empId = empId;
+ this.empName = empName;
+ this.empSalary = empSalary;
+ }
+ @Id
+ @Column(name = "WRONG_NAME")
+ public int getEmpId() {
+ return empId;
+ }
+ public void setEmpId(int empId) {
+ this.empId = empId;
+ }
+ public String getEmpName() {
+ return empName;
+ }
+ public void setEmpName(String empName) {
+ this.empName = empName;
+ }
+ public double getEmpSalary() {
+ return empSalary;
+ }
+ public void setEmpSalary(double empSalary) {
+ this.empSalary = empSalary;
+ }
+ @Override
+ public String toString() {
+ return "Employee Id:="+empId+" Employee Name:="+empName+" Employee Salary:="+empSalary;
+ }
+}//End of Employee.java
--- /dev/null
+package b;
+
+import java.util.Date;
+import java.util.Set;
+
+
+public class Clerk extends Person
+{
+ private Set<Sale> sales;
+ private Date hireDate;
+ private Date termDate;
+}
--- /dev/null
+package b;
+
+import java.util.Set;
+import javax.persistence.Table;
+
+
+@Table(name = "WRONG_NAME")
+public class Customer extends Person
+{
+ public enum CustomerLevel { BRONZE, SILVER, GOLD };
+ private Set<Sale> purchases;
+ private String email;
+ private CustomerLevel level = CustomerLevel.BRONZE;
+}
--- /dev/null
+package b;
+
+
+public class Person
+{
+ private int id;
+ private String name;
+}
--- /dev/null
+package b;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.Set;
+import java.util.UUID;
+
+
+public class Sale
+{
+ private String id;
+ private BigDecimal amount;
+ private Date dateTime;
+ private Set<Clerk> salesClerks;
+ private Customer customer;
+
+ public Sale()
+ {
+ this(UUID.randomUUID().toString());
+ }
+
+ public Sale(String id)
+ {
+ this.id = id;
+ }
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
+
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
+
+ http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
+
+ version="1.0">
+
+
+
+ <!-- id and name mapped in superclass ORM -->
+
+ <entity class="b.Clerk"
+
+ access="FIELD">
+
+ <table name="HMIG_CLERK"/>
+
+ <attributes>
+
+ <basic name="hireDate" optional="false">
+
+ <column name="HIRE_DATE"/>
+
+ <temporal>DATE</temporal>
+
+ </basic>
+
+ <basic name="termDate">
+
+ <column name="TERM_DATE"/>
+
+ <temporal>DATE</temporal>
+
+ </basic>
+
+ <many-to-many name="sales" mapped-by="salesClerks"/>
+
+ </attributes>
+
+ </entity>
+
+</entity-mappings>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
+
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
+
+ http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
+
+ version="1.0">
+
+
+
+ <!-- id and name mapped in superclass ORM -->
+
+ <entity class="b.Customer"
+
+ access="FIELD">
+
+ <table name="HMIG_CUSTOMER"/>
+
+ <attributes>
+
+ <basic name="email">
+
+ <column length="32"/>
+
+ </basic>
+
+ <basic name="level">
+
+ <column length="8"/>
+
+ <enumerated>STRING</enumerated>
+
+ </basic>
+
+
+
+ <one-to-many name="purchases" mapped-by="customer"/>
+
+ </attributes>
+
+ </entity>
+
+</entity-mappings>
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<entity-mappings
+ xmlns="http://java.sun.com/xml/ns/persistence/orm"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
+ version="1.0">
+ <description>My First JPA XML Application</description>
+ <package>a</package>
+ <entity class="a.Employee" name="Employee">
+ <table name="EMPLOYEETABLE"/>
+ <attributes>
+ <id name="empId">
+ <generated-value strategy="TABLE"/>
+ </id>
+ <basic name="empName">
+ <column name="EMP_NAME" length="100"/>
+ </basic>
+ <basic name="empSalary">
+ </basic>
+ </attributes>
+ </entity>
+</entity-mappings>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence
+ xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ version="1.0">
+
+ <!-- taken from https://dzone.com/articles/persisting-entity-classes -->
+ <persistence-unit name="A">
+ <class>a.Employee</class>
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
+ <properties>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
+ </properties>
+ </persistence-unit>
+
+ <!-- taken from http://webdev.jhuep.com/~jcs/legacy-ejava-javaee/coursedocs/605-784-site/docs/content/html/hibernate-migration-orm.html -->
+ <persistence-unit name="B">
+ <mapping-file>META-INF/sale.xml</mapping-file>
+ <mapping-file>META-INF/person.xml</mapping-file>
+ <mapping-file>META-INF/clerk.xml</mapping-file>
+ <mapping-file>META-INF/customer.xml</mapping-file>
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
+ <properties>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/>
+ </properties>
+ </persistence-unit>
+
+</persistence>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
+
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
+
+ http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
+
+ version="1.0">
+
+
+
+ <mapped-superclass class="b.Person"
+
+ access="FIELD">
+
+ <attributes>
+
+ <id name="id">
+
+ <generated-value strategy="IDENTITY"/>
+
+ </id>
+
+ <basic name="name" optional="false">
+
+ <column length="32"/>
+
+ </basic>
+
+ </attributes>
+
+ </mapped-superclass>
+
+</entity-mappings>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
+ http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
+ version="1.0">
+
+ <package>b</package>
+ <access>FIELD</access>
+
+ <entity class="Sale">
+ <table name="HMIG_SALE"/>
+ <attributes>
+ <id name="id">
+ <column length="36"/>
+ </id>
+ <basic name="amount" optional="false">
+ <column precision="7" scale="2"/>
+ </basic>
+ <basic name="dateTime" optional="false">
+ <column name="SALE_TIME"/>
+ <temporal>TIMESTAMP</temporal>
+ </basic>
+
+ <many-to-one name="customer" optional="false">
+ <join-column name="CUSTOMER_ID"/>
+ </many-to-one>
+ <many-to-many name="salesClerks">
+ <join-table name="HMIG_SALE_CLERK">
+ <join-column name="SALE_ID"/>
+ <inverse-join-column name="CLERK_ID"/>
+ </join-table>
+ </many-to-many>
+ </attributes>
+ </entity>
+</entity-mappings>
classes = scanUrls(urls);
for (String className : unit.getManagedClassNames())
classes.add(className);
+ /**
+ * Add mappings from the default mapping-file
+ * <code>META-INF/orm.xml</code>, if present
+ */
+ try
+ {
+ InputStream is = classLoader.getResourceAsStream("META-INF/orm.xml");
+ if (is != null)
+ {
+ getLog().info("Adding default JPA-XML-mapping from META-INF/orm.xml");
+ tracker.track("META-INF/orm.xml", is);
+ sources.addResource("META-INF/orm.xml");
+ }
+ /**
+ * Add mappings from files, that are explicitly configured in the
+ * persistence unit
+ */
+ for (String mapping : unit.getMappingFileNames())
+ {
+ getLog().info("Adding explicitly configured mapping from " + mapping);
+ tracker.track(mapping, classLoader.getResourceAsStream(mapping));
+ sources.addResource(mapping);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new MojoFailureException("Error reading XML-mappings", e);
+ }
}
/** Add the configured/collected annotated classes */
getLog().debug("New or modified package: " + packageName);
else
getLog().debug("Unchanged package: " + packageName);
- getLog().info("Adding annotated package " + packageName);
+ getLog().info("Adding annotations from package " + packageName);
sources.addPackage(packageName);
}
packages.add(packageName);