Commit 1ac7ec4c authored by Thomas Lang's avatar Thomas Lang
Browse files

init commit

parents
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.hibernate.testcasetemplate</groupId>
<artifactId>test-case-template-hibernate-orm5</artifactId>
<version>1.0.0.Final</version>
<name>Hibernate ORM 5 Test Case Template</name>
<properties>
<version.com.h2database>1.3.176</version.com.h2database>
<version.junit>4.11</version.junit>
<version.org.hibernate>5.2.2.Final</version.org.hibernate>
<version.org.slf4j>1.7.2</version.org.slf4j>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${version.org.hibernate}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-testing</artifactId>
<version>${version.org.hibernate}</version>
</dependency>
<!--database driver-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.4</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${version.com.h2database}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${version.org.slf4j}</version>
</dependency>
<!-- Not necessary for ORM 5.2 and above -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${version.org.hibernate}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>${version.org.hibernate}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
package org.hibernate.bugs;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API.
*/
public class JPAUnitTestCase {
private EntityManagerFactory entityManagerFactory;
@Before
public void init() {
entityManagerFactory = Persistence.createEntityManagerFactory( "templatePU" );
}
@After
public void destroy() {
entityManagerFactory.close();
}
// Entities are auto-discovered, so just add them anywhere on class-path
// Add your tests, using standard JUnit.
@Test
public void hhh123Test() throws Exception {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
// Do stuff...
entityManager.getTransaction().commit();
entityManager.close();
}
}
package org.hibernate.bugs;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.junit.Before;
import org.junit.Test;
/**
* This template demonstrates how to develop a standalone test case for Hibernate ORM. Although this is perfectly
* acceptable as a reproducer, usage of ORMUnitTestCase is preferred!
*/
public class ORMStandaloneTestCase {
private SessionFactory sf;
@Before
public void setup() {
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
// Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
.applySetting( "hibernate.show_sql", "true" )
.applySetting( "hibernate.format_sql", "true" )
.applySetting( "hibernate.hbm2ddl.auto", "update" );
Metadata metadata = new MetadataSources( srb.build() )
// Add your entities here.
// .addAnnotatedClass( Foo.class )
.buildMetadata();
sf = metadata.buildSessionFactory();
}
// Add your tests, using standard JUnit.
@Test
public void hhh123Test() throws Exception {
}
}
/*
* Copyright 2014 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hibernate.bugs;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
/**
* This template demonstrates how to develop a test case for Hibernate ORM, using its built-in unit test framework.
* Although ORMStandaloneTestCase is perfectly acceptable as a reproducer, usage of this class is much preferred.
* Since we nearly always include a regression test with bug fixes, providing your reproducer using this method
* simplifies the process.
*
* What's even better? Fork hibernate-orm itself, add your test case directly to a module's unit tests, then
* submit it as a PR!
*/
public class ORMUnitTestCase extends BaseCoreFunctionalTestCase {
// Add your entities here.
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
// Foo.class,
// Bar.class
};
}
// If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
@Override
protected String[] getMappings() {
return new String[] {
// "Foo.hbm.xml",
// "Bar.hbm.xml"
};
}
// If those mappings reside somewhere other than resources/org/hibernate/test, change this.
@Override
protected String getBaseForMappings() {
return "org/hibernate/test/";
}
// Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
@Override
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() );
configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() );
//configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
}
// Add your tests, using standard JUnit.
@Test
public void hhh123Test() throws Exception {
// BaseCoreFunctionalTestCase automatically creates the SessionFactory and provides the Session.
Session s = openSession();
Transaction tx = s.beginTransaction();
// Do stuff...
tx.commit();
s.close();
}
}
package org.hibernate.bugs.db;
import javax.persistence.*;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
/**
* Pojo entity for biller information.
* Stores information concerning the invoice´s biller.
*
* @author tlang
*/
@Entity
@Table(name = "biller", schema = "public",
indexes = {
@Index(name = "index_biller", columnList = "biller"),
@Index(name = "index_billerCampus", columnList = "billerCampus"),
@Index(name = "index_billerContactPerson", columnList = "billerContactPerson"),
@Index(name = "index_billerPostalcode", columnList = "billerPostalcode"),
@Index(name = "index_billerCity", columnList = "billerCity")
})
public class Biller implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private long billerId;
@Column(nullable = false)
@Enumerated
private Campus billerCampus;
@Column(length = 50)
private String billerSalutation;
@Column(nullable = false, length = 150)
private String biller;
@Column(length = 50)
private String billerContactPerson;
@Column(length = 50)
private String billerContactDetails;
@Column(nullable = false, length = 100)
private String billerStreet;
@Column(length = 50)
private String billerBox;
@Column(nullable = false, length = 10)
private String billerPostalcode;
@Column(nullable = false, length = 50)
private String billerCity;
@Column(nullable = false, length = 50)
private String billerCountry;
@Column(nullable = false, length = 50)
private String billerWeb;
@Column(nullable = false)
@Embedded
private Information information;
@OneToMany(cascade = CascadeType.ALL,
mappedBy = "biller", fetch = FetchType.LAZY, orphanRemoval = true)
private Set<Invoice> invoiceSet;
/**
* Standard Constructor.
*/
public Biller() {
this.billerCampus = Campus.THD;
this.invoiceSet = new HashSet<>();
this.information = new Information();
}
/**
* Compares this instance with another instance of this.
*
* @param o another instance
* @return boolean
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Biller biller = (Biller) o;
return billerId == biller.billerId;
}
/**
* Computes a hash code for this instance.
*
* @return the hash code
*/
@Override
public int hashCode() {
return Objects.hash(billerId);
}
/**
* Readable version of the current instance.
*
* @return String
*/
@Override
public String toString() {
return String.format("%s %s, %s, %s", biller, billerStreet, billerPostalcode, billerCity);
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public long getBillerId() {
return billerId;
}
public void setBillerId(long billerId) {
this.billerId = billerId;
}
public Campus getBillerCampus() {
return billerCampus;
}
public void setBillerCampus(Campus billerCampus) {
this.billerCampus = billerCampus;
}
public String getBillerSalutation() {
return billerSalutation;
}
public void setBillerSalutation(String billerSalutation) {
this.billerSalutation = billerSalutation;
}
public String getBiller() {
return biller;
}
public void setBiller(String biller) {
this.biller = biller;
}
public String getBillerContactPerson() {
return billerContactPerson;
}
public void setBillerContactPerson(String billerContactPerson) {
this.billerContactPerson = billerContactPerson;
}
public String getBillerContactDetails() {
return billerContactDetails;
}
public void setBillerContactDetails(String billerContactDetails) {
this.billerContactDetails = billerContactDetails;
}
public String getBillerStreet() {
return billerStreet;
}
public void setBillerStreet(String billerStreet) {
this.billerStreet = billerStreet;
}
public String getBillerBox() {
return billerBox;
}
public void setBillerBox(String billerBox) {
this.billerBox = billerBox;
}
public String getBillerPostalcode() {
return billerPostalcode;
}
public void setBillerPostalcode(String billerPostalcode) {
this.billerPostalcode = billerPostalcode;
}
public String getBillerCity() {
return billerCity;
}
public void setBillerCity(String billerCity) {
this.billerCity = billerCity;
}
public String getBillerCountry() {
return billerCountry;
}
public void setBillerCountry(String billerCountry) {
this.billerCountry = billerCountry;
}
public String getBillerWeb() {
return billerWeb;
}
public void setBillerWeb(String billerWeb) {
this.billerWeb = billerWeb;
}
public Information getInformation() {
return information;
}
public void setInformation(Information information) {
this.information = information;
}
public Set<Invoice> getInvoiceSet() {
return invoiceSet;
}
public void setInvoiceSet(Set<Invoice> invoiceSet) {
this.invoiceSet = invoiceSet;
}
}
\ No newline at end of file
package org.hibernate.bugs.db;
/**
* Enum holding the current Campus structure.
*
* @author tlang
*/
public enum Campus {
THD("Technische Hochschule Deggendorf"),
GCBK("Gesundheitscampus Bad Kötzting"),
TSZWBG("Technologie- und Studienzentrum Weißenburg"),
TCF("Technologie Campus Freyung"),
TCT("Technologie Campus Teisnach"),
TCG("Technologie Campus Grafenau"),
TCC("Technologie Campus Cham"),
TAZS("Technologie Anwender Zentrum Spiegelau"),
CSM("Campus Schloss Mariakirchen");
private final String label;
private final String value;
/**
* package-private standard constructor.
* building up the dto
*
* @param label a given label
*/
Campus(String label) {
this.label = label;
this.value = this.name();
}
public String getLabel() {
return label;
}
public String getValue() {
return value;
}
/**
* to string representation of the current instance.
*
* @return String
*/
@Override
public String toString() {
return this.getLabel();
}
}
package org.hibernate.bugs.db;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* Modelclass for Entity Information.
* Stores some general entity information.
*
* @author tlang
*/
@Embeddable
public class Information implements Serializable {
@Column(nullable = false, length = 50)
private String createdBy;
@Column(nullable = false, length = 50)
private String modifiedBy;
@Column(nullable = false)
private LocalDateTime creationDate;
@Column(nullable = false)
private LocalDateTime modificationDate;
/**
* Constructs a new information instance.
*/
public Information() {
creationDate = LocalDateTime.now();
modificationDate = LocalDateTime.now();
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getModifiedBy() {
return modifiedBy;
}
public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}
public LocalDateTime getCreationDate() {
return creationDate;
}
public void setCreationDate(LocalDateTime creationDate) {
this.creationDate = creationDate;
}
public LocalDateTime getModificationDate() {
return modificationDate;
}
public void setModificationDate(LocalDateTime modificationDate) {
this.modificationDate = modificationDate;
}
}
package org.hibernate.bugs.db;
import javax.persistence.*;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
/**
* Pojo entity for invoice.
* Stores information concerning the invoice.
*
* @author tlang
*/
@Entity
@Table(name = "invoice", schema = "public",
indexes = {
@Index(name = "index_bookingTag", columnList = "bookingTag"),
@Index(name = "index_invoiceApiGroups", columnList = "invoiceApiGroups"),