From: Kai Moritz Date: Sat, 19 Dec 2015 17:02:02 +0000 (+0100) Subject: Mappings from JPA-mapping-files are considered X-Git-Tag: hibernate-maven-plugin-2.0.0~10 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=08649780d2cd70f2861298d683aa6b1945d43cda;p=hibernate-maven-plugin Mappings from JPA-mapping-files are considered --- diff --git a/src/it/multiple-persistence-units/pom.xml b/src/it/multiple-persistence-units/pom.xml new file mode 100644 index 00000000..1ceb830c --- /dev/null +++ b/src/it/multiple-persistence-units/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + de.juplo + multiple-persistence-units + Hibernate 4 Dependency-Test + 1.0-SNAPSHOT + + + @project.version@ + + + + + org.hibernate.javax.persistence + hibernate-jpa-2.1-api + 1.0.0.Final + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + utf8 + true + + + + de.juplo + hibernate-maven-plugin + ${hibernate-maven-plugin.version} + + + Create A + + create + + + A + a-create.sql + + + + Drop B + + drop + + + B + b-drop.sql + + + + Create B + + create + + + B + b-create.sql + + + + + false + true + + + + + diff --git a/src/it/multiple-persistence-units/src/main/java/a/Employee.java b/src/it/multiple-persistence-units/src/main/java/a/Employee.java new file mode 100644 index 00000000..2232a644 --- /dev/null +++ b/src/it/multiple-persistence-units/src/main/java/a/Employee.java @@ -0,0 +1,41 @@ +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 diff --git a/src/it/multiple-persistence-units/src/main/java/b/Clerk.java b/src/it/multiple-persistence-units/src/main/java/b/Clerk.java new file mode 100644 index 00000000..39d97e76 --- /dev/null +++ b/src/it/multiple-persistence-units/src/main/java/b/Clerk.java @@ -0,0 +1,12 @@ +package b; + +import java.util.Date; +import java.util.Set; + + +public class Clerk extends Person +{ + private Set sales; + private Date hireDate; + private Date termDate; +} diff --git a/src/it/multiple-persistence-units/src/main/java/b/Customer.java b/src/it/multiple-persistence-units/src/main/java/b/Customer.java new file mode 100644 index 00000000..8b17b5ba --- /dev/null +++ b/src/it/multiple-persistence-units/src/main/java/b/Customer.java @@ -0,0 +1,14 @@ +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 purchases; + private String email; + private CustomerLevel level = CustomerLevel.BRONZE; +} diff --git a/src/it/multiple-persistence-units/src/main/java/b/Person.java b/src/it/multiple-persistence-units/src/main/java/b/Person.java new file mode 100644 index 00000000..82dde346 --- /dev/null +++ b/src/it/multiple-persistence-units/src/main/java/b/Person.java @@ -0,0 +1,8 @@ +package b; + + +public class Person +{ + private int id; + private String name; +} diff --git a/src/it/multiple-persistence-units/src/main/java/b/Sale.java b/src/it/multiple-persistence-units/src/main/java/b/Sale.java new file mode 100644 index 00000000..088f51dd --- /dev/null +++ b/src/it/multiple-persistence-units/src/main/java/b/Sale.java @@ -0,0 +1,26 @@ +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 salesClerks; + private Customer customer; + + public Sale() + { + this(UUID.randomUUID().toString()); + } + + public Sale(String id) + { + this.id = id; + } +} \ No newline at end of file diff --git a/src/it/multiple-persistence-units/src/main/resources/META-INF/clerk.xml b/src/it/multiple-persistence-units/src/main/resources/META-INF/clerk.xml new file mode 100644 index 00000000..3f1c618e --- /dev/null +++ b/src/it/multiple-persistence-units/src/main/resources/META-INF/clerk.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + DATE + + + + + + + + DATE + + + + + + + + + + diff --git a/src/it/multiple-persistence-units/src/main/resources/META-INF/customer.xml b/src/it/multiple-persistence-units/src/main/resources/META-INF/customer.xml new file mode 100644 index 00000000..c21eabc3 --- /dev/null +++ b/src/it/multiple-persistence-units/src/main/resources/META-INF/customer.xml @@ -0,0 +1,48 @@ + + + + + + + + + + +
+ + + + + + + + + + + + + + STRING + + + + + + + + + + + + + diff --git a/src/it/multiple-persistence-units/src/main/resources/META-INF/orm.xml b/src/it/multiple-persistence-units/src/main/resources/META-INF/orm.xml new file mode 100644 index 00000000..fa5412b0 --- /dev/null +++ b/src/it/multiple-persistence-units/src/main/resources/META-INF/orm.xml @@ -0,0 +1,22 @@ + + + My First JPA XML Application + a + +
+ + + + + + + + + + + + diff --git a/src/it/multiple-persistence-units/src/main/resources/META-INF/persistence.xml b/src/it/multiple-persistence-units/src/main/resources/META-INF/persistence.xml new file mode 100644 index 00000000..bf8c9233 --- /dev/null +++ b/src/it/multiple-persistence-units/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,28 @@ + + + + + + a.Employee + true + + + + + + + + META-INF/sale.xml + META-INF/person.xml + META-INF/clerk.xml + META-INF/customer.xml + true + + + + + + diff --git a/src/it/multiple-persistence-units/src/main/resources/META-INF/person.xml b/src/it/multiple-persistence-units/src/main/resources/META-INF/person.xml new file mode 100644 index 00000000..79a92ed5 --- /dev/null +++ b/src/it/multiple-persistence-units/src/main/resources/META-INF/person.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/it/multiple-persistence-units/src/main/resources/META-INF/sale.xml b/src/it/multiple-persistence-units/src/main/resources/META-INF/sale.xml new file mode 100644 index 00000000..57e848e4 --- /dev/null +++ b/src/it/multiple-persistence-units/src/main/resources/META-INF/sale.xml @@ -0,0 +1,36 @@ + + + + b + FIELD + + +
+ + + + + + + + + + TIMESTAMP + + + + + + + + + + + + + + diff --git a/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java b/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java index 09bd83d4..22959683 100644 --- a/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java @@ -542,6 +542,34 @@ public abstract class AbstractSchemaMojo extends AbstractMojo classes = scanUrls(urls); for (String className : unit.getManagedClassNames()) classes.add(className); + /** + * Add mappings from the default mapping-file + * META-INF/orm.xml, 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 */ @@ -1053,7 +1081,7 @@ public abstract class AbstractSchemaMojo extends AbstractMojo 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);