diff --git a/P/Sda1/Jpa/LectureOperations/pom.xml b/P/Sda1/Jpa/LectureOperations/pom.xml index 4e70b3a04ad5667bf0f1702596019a7830131f8b..15b44200685bd23b73cdcd1d6a7f62bb7293f3ce 100644 --- a/P/Sda1/Jpa/LectureOperations/pom.xml +++ b/P/Sda1/Jpa/LectureOperations/pom.xml @@ -1,70 +1,81 @@ -<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> - - <parent> - <groupId>de.hdm-stuttgart.mi</groupId> - <artifactId>lecturenotes-pom</artifactId> - <version>1.0</version> - <relativePath>../../../pom.xml</relativePath> - </parent> - - <groupId>de.hdm-stuttgart.mi.sda1</groupId> - <artifactId>lecture-operations</artifactId> - <version>0.0.1</version> - <packaging>jar</packaging> - - <name>Lecture-operations</name> - - <url>http://www.mi.hdm-stuttgart.de/freedocs</url> - - <dependencies> - - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-entitymanager</artifactId> - <version>5.0.0.CR1</version> - </dependency> - - <dependency> - <groupId>org.hibernate.javax.persistence</groupId> - <artifactId>hibernate-jpa-2.1-api</artifactId> - <version>1.0.0.Final</version> - </dependency> - - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-c3p0</artifactId> - <version>5.0.0.CR1</version> - </dependency> - - <dependency> - <groupId>mysql</groupId> - <artifactId>mysql-connector-java</artifactId> - <version>${mysql.mysql-connector-java.version}</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> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <version>2.10.1</version> - <configuration/> - </plugin> - - </plugins> - </build> +<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> + + <parent> + <groupId>de.hdm-stuttgart.mi</groupId> + <artifactId>lecturenotes-pom</artifactId> + <version>1.0</version> + <relativePath>../../../pom.xml</relativePath> + </parent> + + <groupId>de.hdm-stuttgart.mi.sda1</groupId> + <artifactId>lecture-operations</artifactId> + <version>0.9</version> + <packaging>jar</packaging> + + <name>lecture-operations</name> + + <url>http://www.mi.hdm-stuttgart.de/freedocs</url> + + <dependencies> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-entitymanager</artifactId> + <version>5.1.0.Final</version> + </dependency> + + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.38</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.6</version> + </dependency> + + <!-- Required for executable jar generation to avoid ClassNotFoundException: + com.fasterxml.jackson.core.type.TypeReference and similar dependency problems. --> + + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <version>2.7.5</version> + </dependency> + + </dependencies> + + <build> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.5.1</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.10.3</version> + <configuration /> + </plugin> + + </plugins> + </build> </project> diff --git a/P/Sda1/Jpa/LectureOperations/src/main/java/de/hdm_stuttgart/mi/sda1/hiberjpa/PersistDriver.java b/P/Sda1/Jpa/LectureOperations/src/main/java/de/hdm_stuttgart/mi/sda1/hiberjpa/PersistDriver.java index ee461dd35214f8ff49851541f2635bbf1be25933..839dfe2f1ebb2b8928584eb30ddb660021d265ee 100644 --- a/P/Sda1/Jpa/LectureOperations/src/main/java/de/hdm_stuttgart/mi/sda1/hiberjpa/PersistDriver.java +++ b/P/Sda1/Jpa/LectureOperations/src/main/java/de/hdm_stuttgart/mi/sda1/hiberjpa/PersistDriver.java @@ -34,5 +34,6 @@ public class PersistDriver { } em.close(); + emFactory.close(); } } diff --git a/P/Sda1/Jpa/LectureOperations/src/main/java/de/hdm_stuttgart/mi/sda1/hiberjpa/ReadAllLecturesCriteriaDriver.java b/P/Sda1/Jpa/LectureOperations/src/main/java/de/hdm_stuttgart/mi/sda1/hiberjpa/ReadAllLecturesCriteriaDriver.java index 1100329b174b78eb29473693b19d9a7466dc8859..181dc7dc1209cfd893890fe77e150d055498cfa9 100644 --- a/P/Sda1/Jpa/LectureOperations/src/main/java/de/hdm_stuttgart/mi/sda1/hiberjpa/ReadAllLecturesCriteriaDriver.java +++ b/P/Sda1/Jpa/LectureOperations/src/main/java/de/hdm_stuttgart/mi/sda1/hiberjpa/ReadAllLecturesCriteriaDriver.java @@ -48,5 +48,6 @@ public class ReadAllLecturesCriteriaDriver { } em.close(); + emFactory.close(); } } diff --git a/P/Sda1/Jpa/LectureOperations/src/main/java/de/hdm_stuttgart/mi/sda1/hiberjpa/ReadAllLecturesJpqlDriver.java b/P/Sda1/Jpa/LectureOperations/src/main/java/de/hdm_stuttgart/mi/sda1/hiberjpa/ReadAllLecturesJpqlDriver.java index b24788607ef94e451c10469d24a1e4ea3305d49c..5c7c30ea89c31f3fa1bd15988afe07d4c1bb1856 100644 --- a/P/Sda1/Jpa/LectureOperations/src/main/java/de/hdm_stuttgart/mi/sda1/hiberjpa/ReadAllLecturesJpqlDriver.java +++ b/P/Sda1/Jpa/LectureOperations/src/main/java/de/hdm_stuttgart/mi/sda1/hiberjpa/ReadAllLecturesJpqlDriver.java @@ -41,5 +41,6 @@ public class ReadAllLecturesJpqlDriver { } em.close(); + emFactory.close(); } } diff --git a/P/Sda1/Jpa/LectureOperations/src/main/resources/META-INF/persistence.xml b/P/Sda1/Jpa/LectureOperations/src/main/resources/META-INF/persistence.xml index 69d3228f3cf1cbe457ee510ff140da9ea06d1969..7b9d657cc9273f84aa726546defefc7d89da2b68 100644 --- a/P/Sda1/Jpa/LectureOperations/src/main/resources/META-INF/persistence.xml +++ b/P/Sda1/Jpa/LectureOperations/src/main/resources/META-INF/persistence.xml @@ -1,57 +1,119 @@ -<persistence 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" - version="2.1"> - <persistence-unit name="jpa-recreate" transaction-type="RESOURCE_LOCAL"> - <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> +<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="jpa-recreate"> + + <!-- + Hibernate will scan your classpath for mapped classes and add them automatically + to your persistence unit. + --> + <exclude-unlisted-classes>false</exclude-unlisted-classes> + + <!-- + setting the previous option "exclude-unlisted-classes" to 'true' requires entity classes to + be listed explicitely. You may want to uncomment the following definition and add more classes. + + <class>de.mi.hdm_stuttgart.Airline</class> + --> + + <!-- + Standard or vendor-specific options can be set as properties on a persistence unit. + Any standard properties have the <code>javax.persistence</code> name prefix, Hibernate's + settings use <code>hibernate</code> + --> <properties> - <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/hdm" /> - <property name="javax.persistence.jdbc.user" value="hdmuser" /> - <property name="javax.persistence.jdbc.password" value="XYZ" /> - <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> - - <property name="hibernate.show_sql" value="true" /> - <property name="hibernate.format_sql" value="true" /> + <!-- + JDBC database connection parameter + --> + <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> + <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/hdm?useSSL=false"/> + <property name="javax.persistence.jdbc.user" value="hdmuser"/> + <property name="javax.persistence.jdbc.password" value="XYZ"/> + + <!-- + The JPA engine should drop and re-create the SQL schema in the database + automatically when it boots. This is ideal for automated testing, when + you want to work with a clean database for every test run. + --> + <property + name="javax.persistence.schema-generation.database.action" + value="drop-and-create"/> + + <!-- + When printing SQL in logs, let Hibernate format the SQL nicely and generate + comments into the SQL string so we know why Hibernate executed the SQL statement. + --> + <property name="hibernate.format_sql" value="true"/> + <property name="hibernate.use_sql_comments" value="true"/> + + <!-- Choose Mysql's innodb backend --> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> - <property name="hibernate.hbm2ddl.auto" value="create-drop" /> - - <!-- Configuring Connection Pool --> - <property name="hibernate.c3p0.min_size" value="5" /> - <property name="hibernate.c3p0.max_size" value="20" /> - <property name="hibernate.c3p0.timeout" value="500" /> - <property name="hibernate.c3p0.max_statements" value="50" /> - <property name="hibernate.c3p0.idle_test_period" value="2000" /> - + <!-- Enable Hibernate scanning for entity classes and adding them automatically + but not for hbm.xml files. --> + <property name="hibernate.archive.autodetection" value="class"/> + </properties> </persistence-unit> - - <persistence-unit name="jpa-update" transaction-type="RESOURCE_LOCAL"> - <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> - + + <persistence-unit name="jpa-update"> + + <!-- + Hibernate will scan your classpath for mapped classes and add them automatically + to your persistence unit. + --> + <exclude-unlisted-classes>false</exclude-unlisted-classes> + + <!-- + setting the previous option "exclude-unlisted-classes" to 'true' requires entity classes to + be listed explicitely. You may want to uncomment the following definition and add more classes. + + <class>de.mi.hdm_stuttgart.Airline</class> + --> + + <!-- + Standard or vendor-specific options can be set as properties on a persistence unit. + Any standard properties have the <code>javax.persistence</code> name prefix, Hibernate's + settings use <code>hibernate</code> + --> <properties> - <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/hdm" /> - <property name="javax.persistence.jdbc.user" value="hdmuser" /> - <property name="javax.persistence.jdbc.password" value="XYZ" /> - <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> - - <property name="hibernate.show_sql" value="true" /> - <property name="hibernate.format_sql" value="true" /> + <!-- + JDBC database connection parameter + --> + <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> + <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/hdm?useSSL=false"/> + <property name="javax.persistence.jdbc.user" value="hdmuser"/> + <property name="javax.persistence.jdbc.password" value="XYZ"/> + + <!-- + The JPA engine should drop and re-create the SQL schema in the database + automatically when it boots. This is ideal for automated testing, when + you want to work with a clean database for every test run. + --> + <property + name="javax.persistence.schema-generation.database.action" + value="update"/> + + <!-- + When printing SQL in logs, let Hibernate format the SQL nicely and generate + comments into the SQL string so we know why Hibernate executed the SQL statement. + --> + <property name="hibernate.format_sql" value="true"/> + <property name="hibernate.use_sql_comments" value="true"/> + + <!-- Choose Mysql's innodb backend --> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> - <property name="hibernate.hbm2ddl.auto" value="update" /> - - <!-- Configuring Connection Pool --> - <property name="hibernate.c3p0.min_size" value="5" /> - <property name="hibernate.c3p0.max_size" value="20" /> - <property name="hibernate.c3p0.timeout" value="500" /> - <property name="hibernate.c3p0.max_statements" value="50" /> - <property name="hibernate.c3p0.idle_test_period" value="2000" /> - + <!-- Enable Hibernate scanning for entity classes and adding them automatically + but not for hbm.xml files. --> + <property name="hibernate.archive.autodetection" value="class"/> + </properties> </persistence-unit> - </persistence> \ No newline at end of file