From: Kai Moritz Date: Sat, 9 Apr 2016 09:02:59 +0000 (+0200) Subject: Added additional integration test provided by Fabio Heer X-Git-Tag: hibernate-maven-plugin-2.1.0~24 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=5726d98865ea5257e5829355d8e4f9f42fbe0b53;p=hibernate-maven-plugin Added additional integration test provided by Fabio Heer --- diff --git a/pom.xml b/pom.xml index 3d3c10d7..2356d057 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,10 @@ Andreas Kuhtz andreas.kuhtz@gmail.com + + Heer Fabio + fabio.heer@dvbern.ch + + + + + + + + + + + + diff --git a/src/it/multimodule/pom.xml b/src/it/multimodule/pom.xml new file mode 100644 index 00000000..349daa8b --- /dev/null +++ b/src/it/multimodule/pom.xml @@ -0,0 +1,164 @@ + + + 4.0.0 + + ch.dvbern.demo + hibernate-maven-plugin + 0.1.0-SNAPSHOT + pom + + Multimodule Project + + + + + org.mariadb.jdbc.Driver + jdbc:mysql://localhost/hmp + test + test + + 1.3.7 + 5.1.0.Final + + 1.7.10 + + + + + + org.wildfly.bom + jboss-javaee-7.0-wildfly + 10.0.0.CR2 + pom + import + + + + org.hibernate + hibernate-entitymanager + ${version.hibernate} + + + dom4j + dom4j + + + + + + com.google.code.findbugs + annotations + 3.0.0 + + + com.google.guava + guava + 19.0 + + + org.hibernate + hibernate-core + ${version.hibernate} + + + org.mariadb.jdbc + mariadb-java-client + ${version.mysqldriver} + + + + org.apache.commons + commons-lang3 + 3.3.2 + + + commons-configuration + commons-configuration + 1.10 + + + commons-io + commons-io + 2.4 + + + + + ${project.groupId} + shared + ${project.version} + + + + org.slf4j + slf4j-api + ${version.slf4j} + + + org.slf4j + slf4j-ext + ${version.slf4j} + + + org.slf4j + slf4j-simple + ${version.slf4j} + + + org.slf4j + jcl-over-slf4j + ${version.slf4j} + + + org.slf4j + log4j-over-slf4j + ${version.slf4j} + + + + + org.hibernate + hibernate-java8 + ${version.hibernate} + + + + + + + + com.google.code.findbugs + annotations + + + + + + + + de.juplo + hibernate-maven-plugin + @project.version@ + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + -proc:none + + + + + + + + + shared + ejb + + diff --git a/src/it/multimodule/shared/pom.xml b/src/it/multimodule/shared/pom.xml new file mode 100644 index 00000000..2323bd21 --- /dev/null +++ b/src/it/multimodule/shared/pom.xml @@ -0,0 +1,139 @@ + + + + hibernate-maven-plugin + ch.dvbern.demo + 0.1.0-SNAPSHOT + + 4.0.0 + + shared + + + + com.google.guava + guava + + + javax.enterprise + cdi-api + provided + + + org.jboss.spec.javax.ejb + jboss-ejb-api_3.2_spec + provided + + + org.hibernate.javax.persistence + hibernate-jpa-2.1-api + provided + + + org.hibernate + hibernate-entitymanager + ${version.hibernate} + + + javax.validation + validation-api + provided + + + org.apache.commons + commons-lang3 + + + commons-configuration + commons-configuration + + + + + org.hibernate + hibernate-core + provided + + + + org.hibernate + hibernate-jpamodelgen + ${version.hibernate} + provided + true + + + + org.hibernate + hibernate-java8 + + + org.mariadb.jdbc + mariadb-java-client + + + + + + + + org.bsc.maven + maven-processor-plugin + 2.2.4 + + + process + + process + + generate-sources + + + org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor + + + + + + + org.hibernate + hibernate-jpamodelgen + ${version.hibernate} + + + + + + de.juplo + hibernate-maven-plugin + + + + create + + + + + + org.hibernate.dialect.MySQL5Dialect + ch.dvbern.demo.persistence.DemoPhysicalNamingStrategyImpl + + + false + true + true + + ${project.build.directory}/schema.ddl + + true + + + + + + + + + + diff --git a/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/entities/AbstractEntity.java b/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/entities/AbstractEntity.java new file mode 100644 index 00000000..667892b6 --- /dev/null +++ b/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/entities/AbstractEntity.java @@ -0,0 +1,115 @@ +package ch.dvbern.demo.entities; + +import java.io.Serializable; +import java.util.Objects; +import java.util.UUID; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.Version; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.hibernate.Hibernate; + +import ch.dvbern.demo.util.Constants; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +@SuppressWarnings("ClassReferencesSubclass") +@MappedSuperclass +public abstract class AbstractEntity implements Serializable { + + private static final long serialVersionUID = -979317154050183445L; + + @Id + @Column(unique = true, nullable = false, updatable = false, length = Constants.UUID_LENGTH) + @Size(min = Constants.UUID_LENGTH, max = Constants.UUID_LENGTH) + private String id; + + @Version + @NotNull + private long version; + + @Size(max = Constants.UUID_LENGTH) + @Column(nullable = false, length = Constants.UUID_LENGTH) + private String userErstellt; + + @Size(max = Constants.UUID_LENGTH) + @Column(nullable = false, length = Constants.UUID_LENGTH) + private String userMutiert; + + protected AbstractEntity() { + //da wir teilweise schon eine id brauchen bevor die Entities gespeichert werden initialisieren wir die uuid hier + id = UUID.randomUUID().toString(); + } + + public String getId() { + return id; + } + + public void setId(@Nullable String id) { + this.id = id; + } + + // Nullable, da erst im PrePersist gesetzt + public long getVersion() { + return version; + } + + public void setVersion(long version) { + this.version = version; + } + + @Nullable // Nullable, da erst im PrePersist gesetzt + public String getUserErstellt() { + return userErstellt; + } + + public void setUserErstellt(@Nonnull String userErstellt) { + this.userErstellt = userErstellt; + } + + @Nullable // Nullable, da erst im PrePersist gesetzt + public String getUserMutiert() { + return userMutiert; + } + + public void setUserMutiert(@Nonnull String userMutiert) { + this.userMutiert = userMutiert; + } + + @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") + @SuppressFBWarnings(value = "BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS", justification = "Es wird Hibernate.getClass genutzt um von Proxies (LazyInit) die konkrete Klasse zu erhalten") + @Override + public boolean equals(@Nullable Object o) { + if (this == o) { + return true; + } + + if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) { + return false; + } + + AbstractEntity that = (AbstractEntity) o; + + Objects.requireNonNull(getId()); + Objects.requireNonNull(that.getId()); + + return getId().equals(that.getId()); + } + + public int hashCode() { + return getId() != null ? getId().hashCode() : 0; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("id", getId()) + .toString(); + } +} diff --git a/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/entities/Adresse.java b/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/entities/Adresse.java new file mode 100644 index 00000000..f37a79d1 --- /dev/null +++ b/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/entities/Adresse.java @@ -0,0 +1,106 @@ +package ch.dvbern.demo.entities; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.ManyToMany; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +import ch.dvbern.demo.util.Constants; + +/** + * Entitaet zum Speichern von Adressen in der Datenbank. + */ +@Entity +public class Adresse extends AbstractEntity { + + private static final long serialVersionUID = -7687645920281069260L; + + @Size(max = Constants.DB_DEFAULT_MAX_LENGTH) + @Nonnull + @NotNull + @Column(nullable = false, length = Constants.DB_DEFAULT_MAX_LENGTH) + private String strasse = ""; + + @Size(max = Constants.DB_DEFAULT_SHORT_LENGTH) + @Nullable + @Column(nullable = true, length = Constants.DB_DEFAULT_SHORT_LENGTH) + private String hausnummer = null; + + @Size(max = Constants.DB_DEFAULT_MAX_LENGTH) + @Nullable + @Column(nullable = true, length = Constants.DB_DEFAULT_MAX_LENGTH) + private String zusatzzeile = null; + + @Size(max = Constants.DB_DEFAULT_SHORT_LENGTH) + @Nonnull + @NotNull + @Column(nullable = false, length = Constants.DB_DEFAULT_SHORT_LENGTH) + private String plz = ""; + + @Size(max = Constants.DB_DEFAULT_MAX_LENGTH) + @Nonnull + @NotNull + @Column(nullable = false, length = Constants.DB_DEFAULT_MAX_LENGTH) + private String ort = ""; + + @ManyToMany(mappedBy = "adressen") + private List personen = new ArrayList<>(); + + @Nonnull + public String getStrasse() { + return strasse; + } + + public void setStrasse(@Nonnull final String strasse) { + this.strasse = strasse; + } + + @Nullable + public String getHausnummer() { + return hausnummer; + } + + public void setHausnummer(@Nullable final String hausnummer) { + this.hausnummer = hausnummer; + } + + @Nullable + public String getZusatzzeile() { + return zusatzzeile; + } + + public void setZusatzzeile(@Nullable final String zusatzzeile) { + this.zusatzzeile = zusatzzeile; + } + + @Nonnull + public String getPlz() { + return plz; + } + + public void setPlz(@Nonnull final String plz) { + this.plz = plz; + } + + @Nonnull + public String getOrt() { + return ort; + } + + public void setOrt(@Nonnull final String ort) { + this.ort = ort; + } + + public List getPersonen() { + return personen; + } + + public void setPersonen(final List personen) { + this.personen = personen; + } +} diff --git a/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/entities/Person.java b/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/entities/Person.java new file mode 100644 index 00000000..717b038f --- /dev/null +++ b/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/entities/Person.java @@ -0,0 +1,86 @@ +package ch.dvbern.demo.entities; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nonnull; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.ForeignKey; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +import static ch.dvbern.demo.util.Constants.DB_DEFAULT_MAX_LENGTH; + +/** + * Entity fuer personendaten + */ +@Entity +@Table(uniqueConstraints = { + @UniqueConstraint(name = "person_uc1", columnNames = "vorname"), + @UniqueConstraint(name = "person_uc2", columnNames = "userErstellt"), + @UniqueConstraint(name = "person_uc3", columnNames = { "userErstellt", "vorname" }) // FIXME funktioniert nicht +}) +public class Person extends AbstractEntity { + + private static final long serialVersionUID = -9032257320578372570L; + + @Nonnull + @Size(min = 1, max = DB_DEFAULT_MAX_LENGTH) + @Column(nullable = false) + @NotNull + private String vorname = ""; + + @Nonnull + @Size(min = 1, max = DB_DEFAULT_MAX_LENGTH) + @NotNull + @Column(nullable = false) + private String nachname = ""; + + @Nonnull + @ManyToMany + @JoinTable( + name = "personen_adressen", + joinColumns = @JoinColumn(name = "person_id", foreignKey = @ForeignKey(name = "person_fk1")), + inverseJoinColumns = @JoinColumn(name = "adresse_id", foreignKey = @ForeignKey(name = "adresse_fk1")), + indexes = { + @Index(name = "personen_adressen_ix1", columnList = "person_id"), + @Index(name = "personen_adressen_ix2", columnList = "adresse_id") + } + ) +// @org.hibernate.annotations.ForeignKey(name = "person_fk1", inverseName = "adresse_fk1") // TODO ohne die Hibernate spez. Annotation funktioniert das Naming der Foreign Keys nicht + private List adressen = new ArrayList<>(); + + + @Nonnull + public String getVorname() { + return vorname; + } + + public void setVorname(@Nonnull final String vorname) { + this.vorname = vorname; + } + + @Nonnull + public String getNachname() { + return nachname; + } + + public void setNachname(@Nonnull final String nachname) { + this.nachname = nachname; + } + + @Nonnull + public List getAdressen() { + return adressen; + } + + public void setAdressen(@Nonnull final List adressen) { + this.adressen = adressen; + } +} diff --git a/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/persistence/DemoPhysicalNamingStrategyImpl.java b/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/persistence/DemoPhysicalNamingStrategyImpl.java new file mode 100644 index 00000000..7984c7f3 --- /dev/null +++ b/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/persistence/DemoPhysicalNamingStrategyImpl.java @@ -0,0 +1,36 @@ +package ch.dvbern.demo.persistence; + +import java.util.Locale; + +import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; + +public class DemoPhysicalNamingStrategyImpl extends PhysicalNamingStrategyStandardImpl { + + private static final long serialVersionUID = 7069586216789441113L; + + public static final DemoPhysicalNamingStrategyImpl INSTANCE = new DemoPhysicalNamingStrategyImpl(); + + @Override + public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) { + return new Identifier(addUnderscores(name.getText()), name.isQuoted()); + } + + @Override + public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment context) { + return new Identifier(addUnderscores(name.getText()), name.isQuoted()); + } + + + protected static String addUnderscores(String name) { + final StringBuilder buf = new StringBuilder(name.replace('.', '_')); + for (int i = 1; i < buf.length() - 1; i++) { + if (Character.isLowerCase(buf.charAt(i - 1)) && Character.isUpperCase(buf.charAt(i)) + && Character.isLowerCase(buf.charAt(i + 1))) { + buf.insert(i++, '_'); + } + } + return buf.toString().toLowerCase(Locale.ROOT); + } +} diff --git a/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/util/Constants.java b/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/util/Constants.java new file mode 100644 index 00000000..c67dfe01 --- /dev/null +++ b/src/it/multimodule/shared/src/main/java/ch/dvbern/demo/util/Constants.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2013 DV Bern AG, Switzerland + * + * Das vorliegende Dokument, einschliesslich aller seiner Teile, ist urheberrechtlich + * geschuetzt. Jede Verwertung ist ohne Zustimmung der DV Bern AG unzulaessig. Dies gilt + * insbesondere fuer Vervielfaeltigungen, die Einspeicherung und Verarbeitung in + * elektronischer Form. Wird das Dokument einem Kunden im Rahmen der Projektarbeit zur + * Ansicht uebergeben ist jede weitere Verteilung durch den Kunden an Dritte untersagt. + */ + +package ch.dvbern.demo.util; + +/** + * Interface fuer Konstanten. + */ +public interface Constants { + + int DB_DEFAULT_MAX_LENGTH = 255; + int DB_DEFAULT_SHORT_LENGTH = 100; + + int UUID_LENGTH = 36; +} diff --git a/src/it/multimodule/shared/src/main/resources/META-INF/orm.xml b/src/it/multimodule/shared/src/main/resources/META-INF/orm.xml new file mode 100644 index 00000000..b4f4d31d --- /dev/null +++ b/src/it/multimodule/shared/src/main/resources/META-INF/orm.xml @@ -0,0 +1,9 @@ + + + + + +