diff --git a/ws/Archetypes/archetype-catalog.xml b/ws/Archetypes/archetype-catalog.xml index 6ef0a9dfd6d675072805be751afd533c14b0457b..2e6ea6a15b5bc0eba3d96061d3faf35e4cb1ce5a 100644 --- a/ws/Archetypes/archetype-catalog.xml +++ b/ws/Archetypes/archetype-catalog.xml @@ -33,7 +33,7 @@ <archetype> <groupId>de.hdm-stuttgart.mi</groupId> <artifactId>mi-maven-archetype-jpa-hibernate</artifactId> - <version>1.1</version> + <version>1.2</version> <repository>https://maven.mi.hdm-stuttgart.de/Archetypes</repository> <description>Sample JPA project including a database populating Junit test.</description> </archetype> diff --git a/ws/Archetypes/maven-prototype-jpa-hibernate/pom.xml b/ws/Archetypes/maven-prototype-jpa-hibernate/pom.xml index 247624fc47586a5d64e617369376dd0d1fdeddd3..5ab60606eea6a8888aa53d388bf31ba325896b47 100644 --- a/ws/Archetypes/maven-prototype-jpa-hibernate/pom.xml +++ b/ws/Archetypes/maven-prototype-jpa-hibernate/pom.xml @@ -1,108 +1,107 @@ <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> + 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.hdm-stuttgart.mi.sda2</groupId> - <artifactId>maven-prototype-jpa-hibernate</artifactId> - <version>0.0.1-SNAPSHOT</version> - <packaging>jar</packaging> + <groupId>de.hdm-stuttgart.mi.sda2</groupId> + <artifactId>maven-prototype-jpa-hibernate</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>jar</packaging> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> - <name>maven-prototype-jpa-hibernate</name> + <name>maven-prototype-jpa-hibernate</name> - <url>http://www.mi.hdm-stuttgart.de/freedocs/topic/de.hdm_stuttgart.mi.lectures/sd1SectUsingMaven.html</url> + <url>http://www.mi.hdm-stuttgart.de/freedocs/topic/de.hdm_stuttgart.mi.lectures/sd1SectUsingMaven.html</url> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> + <dependencies> - <dependencies> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-entitymanager</artifactId> + <version>5.1.0.Final</version> + </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-entitymanager</artifactId> - <version>5.1.0.Final</version> - </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-jpamodelgen</artifactId> + <version>5.2.0.Final</version> + </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-jpamodelgen</artifactId> - <version>5.2.0.Final</version> - </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.38</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>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> - <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> - <!-- 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> - </dependencies> + <build> + <plugins> - <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> - <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> - - <!-- - JPA 2.0 metamodel generation - See https://docs.jboss.org/hibernate/orm/5.0/topical/html/metamodelgen/MetamodelGenerator.html - also with respect to Eclipse IDE suport. - --> - <compilerArguments> - <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor> - </compilerArguments> - </configuration> - </plugin> + <!-- + JPA 2.0 metamodel generation + See https://docs.jboss.org/hibernate/orm/5.0/topical/html/metamodelgen/MetamodelGenerator.html + also with respect to Eclipse IDE suport. + --> + <compilerArguments> + <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor> + </compilerArguments> + </configuration> + </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <version>1.10</version> - <executions> - <execution> - <id>add-source</id> - <phase>generate-sources</phase> - <goals> - <goal>add-source</goal> - </goals> - <configuration> - <sources> - <!-- - To be configured in Eclipse - Java ompiler - Annotation processing, see - https://docs.jboss.org/hibernate/orm/5.0/topical/html/metamodelgen/MetamodelGenerator.html - --> - <source>target/generated-sources/annotations</source> - </sources> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>1.10</version> + <executions> + <execution> + <id>add-source</id> + <phase>generate-sources</phase> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <!-- + To be configured in Eclipse - Java ompiler - Annotation processing, see + https://docs.jboss.org/hibernate/orm/5.0/topical/html/metamodelgen/MetamodelGenerator.html + --> + <source>target/generated-sources/annotations</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> diff --git a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/Readme.md b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/Readme.md new file mode 100644 index 0000000000000000000000000000000000000000..18171c72098270d1606a57dafc6e2847829da593 --- /dev/null +++ b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/Readme.md @@ -0,0 +1,14 @@ +Hibernate JPA 2 project template +================================ + +General: +-------- + +Archetype defining project. This archetype aims at facilitating +the creation of a basic Hibernate based JPA project. + +See [Readme.md](src/main/resources/archetype-resources/Readme.md) for +details. + +Final success based on +http://maven.apache.org/archetype/maven-archetype-plugin/examples/create-with-property-file.html \ No newline at end of file diff --git a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/Readme.txt b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/Readme.txt deleted file mode 100644 index 7cb02b13c06a54e7f98d697a022f771acc8bd6de..0000000000000000000000000000000000000000 --- a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/Readme.txt +++ /dev/null @@ -1,8 +0,0 @@ -Final success via http://maven.apache.org/archetype/maven-archetype-plugin/examples/create-with-property-file.html - -Create Project from local repository using: - - mvn archetype:generate -DarchetypeCatalog=local -DarchetypeGroupId=de.hdm-stuttgart.mi \ - -DarchetypeArtifactId=mi-maven-archetype-jpa-hibernate -DarchetypeVersion=1.1 \ - -DgroupId=de.mi.hdm_stuttgart -DartifactId=hellojpa -DinteractiveMode=false - diff --git a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/pom.xml b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/pom.xml index 8fbb5587233c55087220a70512ae4b6b2c5f48ff..53f9fc5b402467aa7212b22cd9a0b3c72289fe94 100644 --- a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/pom.xml +++ b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/pom.xml @@ -1,15 +1,15 @@ <?xml version="1.0" encoding="UTF-8"?> <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> + <modelVersion>4.0.0</modelVersion> - <groupId>de.hdm-stuttgart.mi</groupId> - <artifactId>mi-maven-archetype-jpa-hibernate</artifactId> - <version>1.1</version> - <packaging>jar</packaging> + <groupId>de.hdm-stuttgart.mi</groupId> + <artifactId>mi-maven-archetype-jpa-hibernate</artifactId> + <version>1.2</version> + <packaging>jar</packaging> - <name>mi-maven-archetype-jpa-hibernate</name> + <name>mi-maven-archetype-jpa-hibernate</name> - <url>http://www.mi.hdm-stuttgart.de/freedocs/topic/de.hdm_stuttgart.mi.lectures/sd1SectUsingMaven.html</url> + <url>http://www.mi.hdm-stuttgart.de/freedocs/topic/de.hdm_stuttgart.mi.lectures/sd1SectUsingMaven.html</url> <distributionManagement> <!-- This requires configurations in ~/.m2/settings.xml, see local settings.xml.template @@ -25,7 +25,7 @@ <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ssh-external</artifactId> - <version>2.10</version> + <version>3.0.0</version> </extension> </extensions> @@ -34,7 +34,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> - <version>3.5.1</version> + <version>3.7.0</version> <configuration> <source>1.8</source> <target>1.8</target> @@ -42,6 +42,4 @@ </plugin> </plugins> </build> - - </project> diff --git a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/Readme.md b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/Readme.md index 8c1fe3d2769a3a8a19e722bddc208651b12ac5a8..ffa2b2e5d83b3fe9e0f08c9b75203ca954c140cb 100644 --- a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/Readme.md +++ b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/Readme.md @@ -1,24 +1,57 @@ Hibernate JPA 2 project template ================================ +Usage: +------ + mvn archetype:generate -DarchetypeCatalog=local \ + -DarchetypeGroupId=de.hdm-stuttgart.mi \ + -DarchetypeArtifactId=mi-maven-archetype-jpa-hibernate \ + -DarchetypeVersion=1.2 \ + -DgroupId=de.mi.hdm_stuttgart -DartifactId=hellojpa \ + -DinteractiveMode=false + +This requires to set up the MI Maven repository in `~/.m2/settings.xml`: + + <profiles> + <profile> + <id>hdm</id> + <repositories> + <repository> + <id>archetype</id> + <url>https://maven.mi.hdm-stuttgart.de/Archetypes</url> + <releases> + <enabled>true</enabled> + <checksumPolicy>warn</checksumPolicy> + </releases> + <snapshots> + <enabled>true</enabled> + <checksumPolicy>warn</checksumPolicy> + </snapshots> + </repository> + </repositories> + </profile> + </profiles> + + General: -------- This project contains: -* `src/main/resources/META-INF/persistence.xml`<br/> - Defining two persistence units both offering a JDBC database - connection to a Mysql 5 server. You may want to adjust both - database type and connection parameters.<br/> - The first unit will re-create the database schema whereas using - the second will preserve your current database schema. +* `src/main/resources/META-INF/persistence.xml` + + Two persistence units offering a »drop-and-create« + (re-creating schema) and a »strategy_none« (don't touch)JDBC database + connection to a Mysql 5 server. You may want to adjust both database + type and connection parameters. -* -|Class |Package |Description | -|--------------|----------------------|----------------------| -|`Airline` |`$(packageroot).model`|JPA example entity | -|`CreateEntity`|`$(packageroot)` |Create database schema, persist an instance of Airline | -|`SearchByIcao`|`$(packageroot)` |JPA typesafe criteria search demo | -|`EntityTest` |`$(testroot)` |Persisting and re-reading an object by its primary key value | +* Executable classes and tests: + +|Class |Package |Description | +|---------------|----------------------|----------------------| +|`Airline` |`$(packageroot).model`|JPA example entity | +|`CreateAirline`|`$(packageroot)` |Create database schema, persist an instance of Airline | +|`SearchByIcao` |`$(packageroot)` |JPA typesafe criteria search demo | +|`EntityTest` |`$(testroot)` |Persisting and re-reading an object by its primary key value | * `src/main/resources/log4j2.xml` Configuring the log4j subsystem. @@ -31,8 +64,23 @@ metamodel classes like `Airline_.java` during the (http://docs.jboss.org/hibernate/entitymanager/3.6/reference/en/html/querycriteria.html#querycriteria-typedquery) as being outlined in class `$(packageroot)`/`SearchByIcao`. -Eclipse IDE users: ------------------- + +Targets: +-------- + +* `mvn test` + Creating and re-reading a database instance of `Airline`. Connection + parameters being defined twice in + `src/main/resources/META-INF/persistence.xml`. + +* `mvn package` + Creating an executable jar persisting an `Airline` instance to be run + like e.g.: + + java -jar target/intro-1.0-SNAPSHOT.jar + +Special note to Eclipse IDE users: +---------------------------------- On initial archetype based project generation your new project's class »`SearchByIcao`« reveals a compile time error indicating a missing class `Airline_`. Possible resolutions: diff --git a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/pom.xml b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/pom.xml index 69892d78f4adf35241c38821f8d4bfe9b8027b40..d9c433d7d27b972e89c56d7c1feaf42844010dd4 100644 --- a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/pom.xml +++ b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/pom.xml @@ -1,152 +1,152 @@ <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>${groupId}</groupId> - <artifactId>${artifactId}</artifactId> - <version>${version}</version> - <packaging>jar</packaging> - - <name>${artifactId}</name> - - <url>http://www.mi.hdm-stuttgart.de/freedocs/topic/de.hdm_stuttgart.mi.lectures/sd1SectUsingMaven.html</url> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-core</artifactId> - <version>5.2.5.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.7</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.6.0</version> - <configuration> - <source>1.8</source> - <target>1.8</target> - <compilerArgument>-proc:none</compilerArgument> - </configuration> - </plugin> - - <plugin> - <groupId>org.bsc.maven</groupId> - <artifactId>maven-processor-plugin</artifactId> - <version>3.2.0</version> - - <executions> - <execution> - <id>process</id> - <goals> - <goal>process</goal> - </goals> - <phase>generate-sources</phase> - <configuration> - <outputDirectory>${project.build.directory}/metamodel</outputDirectory> - <processors> - <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor> - </processors> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-jpamodelgen</artifactId> - <version>5.2.5.Final</version> - </dependency> - </dependencies> - </plugin> - - <!-- Build helper plugin to add generated sources to classpath --> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <version>1.12</version> - <executions> - <execution> - <id>add-source</id> - <phase>generate-sources</phase> - <goals> - <goal>add-source</goal> - </goals> - <configuration> - <sources> - <source>${project.build.directory}/metamodel</source> - </sources> - </configuration> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <version>2.10.4</version> - <configuration /> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>2.4.3</version> - <configuration> - <transformers> - <transformer - implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> - <manifestEntries> - <Main-Class>${package}.CreateEntity</Main-Class> - </manifestEntries> - </transformer> - </transformers> - </configuration> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>shade</goal> - </goals> - </execution> - </executions> - </plugin> - - </plugins> - </build> -</project> + 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>${groupId}</groupId> + <artifactId>${artifactId}</artifactId> + <version>${version}</version> + <packaging>jar</packaging> + + <name>${artifactId}</name> + + <url>http://www.mi.hdm-stuttgart.de/freedocs/topic/de.hdm_stuttgart.mi.lectures/sd1SectUsingMaven.html</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + <version>5.2.12.Final</version> + </dependency> + + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>6.0.6</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.10.0</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.9.3</version> + </dependency> + <!-- + https://stackoverflow.com/questions/27412287/junit-tests-fail-with-java-error-when-using-intellij-within-maven-module-after-a#answer-34374834 + --> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-jpamodelgen</artifactId> + <version>5.2.12.Final</version> + <scope>provided</scope> + </dependency> + + </dependencies> + + <build> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.7.0</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + <compilerArgument>-proc:none</compilerArgument> + </configuration> + </plugin> + + <plugin> + <groupId>org.bsc.maven</groupId> + <artifactId>maven-processor-plugin</artifactId> + <version>3.2.0</version> + + <executions> + <execution> + <id>process</id> + <goals> + <goal>process</goal> + </goals> + <phase>generate-sources</phase> + <configuration> + <outputDirectory>${project.build.directory}/metamodel</outputDirectory> + <processors> + <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor> + </processors> + </configuration> + </execution> + </executions> + </plugin> + + <!-- Build helper plugin to add generated sources to classpath --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>3.0.0</version> + <executions> + <execution> + <id>add-source</id> + <phase>generate-sources</phase> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>${project.build.directory}/metamodel</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>3.0.0</version> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>3.1.0</version> + <configuration> + <transformers> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <manifestEntries> + <Main-Class>${package}.CreateAirline</Main-Class> + </manifestEntries> + </transformer> + </transformers> + </configuration> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file diff --git a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/src/main/java/CreateAirline.java b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/src/main/java/CreateAirline.java index 7a2328b1f9351b02a77694b736cb2d92a0a899ef..0f490116077462631a7dced3f2c0c7be5ebad7cd 100644 --- a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/src/main/java/CreateAirline.java +++ b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/src/main/java/CreateAirline.java @@ -1,7 +1,7 @@ #set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}; + #set( $symbol_dollar = '$' ) + #set( $symbol_escape = '\' ) + package ${package}; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; @@ -14,32 +14,32 @@ import ${package}.model.Airline; public class CreateAirline { - static final Logger log = LogManager.getLogger(CreateAirline.class); - - /** - * This refers to a corresponding element <persistence-unit name = "strategy_drop-and-create" > - * in META-INF/persistence.xml re-creating the relational database schema. - */ - static public final String PERSISTENCE_UNIT_NAME = "strategy_drop-and-create"; - /** - * @param args Unused - */ - public static void main( String[] args ) { - - final EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); - final EntityManager em = factory.createEntityManager(); - - log.info("Begin transaction"); - em.getTransaction().begin(); - final Airline lh = new Airline("Lufthansa", "DLH"); - - em.persist(lh); - em.getTransaction().commit(); - log.info("Committed transaction"); - - em.close(); - - // See http://stackoverflow.com/questions/21645516/program-using-hibernate-does-not-terminate - factory.close(); - } -} + static private final Logger log = LogManager.getLogger(CreateAirline.class); + + /** + * This refers to a corresponding element <persistence-unit name = "strategy_drop-and-create" > + * in META-INF/persistence.xml re-creating the relational database schema. + */ + static public final String PERSISTENCE_UNIT_NAME = "strategy_drop-and-create"; + /** + * @param args Unused + */ + public static void main( String[] args ) { + + final EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); + final EntityManager em = factory.createEntityManager(); + + log.info("Begin transaction"); + em.getTransaction().begin(); + final Airline lh = new Airline("Lufthansa", "DLH"); + + em.persist(lh); + em.getTransaction().commit(); + log.info("Committed transaction"); + + em.close(); + + // See http://stackoverflow.com/questions/21645516/program-using-hibernate-does-not-terminate + factory.close(); + } +} \ No newline at end of file diff --git a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/src/main/java/SearchByIcao.java b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/src/main/java/SearchByIcao.java index 69d1ab8b78a8d14d4acccb3824221e70425ad48a..e350d11fbbbb02fd3cfc2f09099e2eeef6353809 100644 --- a/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/src/main/java/SearchByIcao.java +++ b/ws/Archetypes/mi-maven-archetype-jpa-hibernate/src/main/resources/archetype-resources/src/main/java/SearchByIcao.java @@ -1,7 +1,7 @@ #set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -package ${package}; + #set( $symbol_dollar = '$' ) + #set( $symbol_escape = '\' ) + package ${package}; import java.util.List; @@ -20,47 +20,45 @@ import ${package}.model.Airline; import ${package}.model.Airline_; // See comment further below. public class SearchByIcao { - static final Logger log = LogManager.getLogger(SearchByIcao.class); - - /** - * This refers to a corresponding element <persistence-unit name = "strategy_none" > - * in META-INF/persistence.xml preserving the relational database schema. - */ - static public final String PERSISTENCE_UNIT_NAME = "strategy_none"; - /** - * @param args Unused - */ - public static void main( String[] args ) { - - - final EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); - final EntityManager em = factory.createEntityManager(); - final CriteriaBuilder cb = factory.getCriteriaBuilder(); - - log.info("Read airlines by icao code"); - em.getTransaction().begin(); - - - final CriteriaQuery<Airline> criteria = cb.createQuery( Airline.class ); - final Root<Airline> airlineRoot = criteria.from( Airline.class ); - - // The subsequent line of code requires "mvn generate-sources" or equivalent triggering the metamodel generator - // when working in Eclipse. You may want to right click on your project root choosing - // - // "Run As" --> "Maven generate-sources". - // - // This step is being required whenever changes to your model classes in mi.intro.jpastart.model happen. - - criteria.where(cb.equal( airlineRoot.get( Airline_.icaoCode), "DLH" )); - final List<Airline> airlines = em.createQuery( criteria ).getResultList(); - for (final Airline airline : airlines ) { - System.out.println(airline); - } - em.getTransaction().commit(); - log.info("Read completed"); - - em.close(); - - factory.close(); - } + static private final Logger log = LogManager.getLogger(SearchByIcao.class); + + /** + * This refers to a corresponding element <persistence-unit name = "strategy_none" > + * in META-INF/persistence.xml preserving the relational database schema. + */ + static private final String PERSISTENCE_UNIT_NAME = "strategy_none"; + /** + * @param args Unused + */ + public static void main( String[] args ) { + + final EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); + final EntityManager em = factory.createEntityManager(); + final CriteriaBuilder cb = factory.getCriteriaBuilder(); + + log.info("Read airlines by icao code"); + em.getTransaction().begin(); + + final CriteriaQuery<Airline> criteria = cb.createQuery( Airline.class ); + final Root<Airline> airlineRoot = criteria.from( Airline.class ); + + // Eclipse users note: The subsequent line of code requires "mvn generate-sources" or equivalent + // triggering the metamodel generator. You may want to right click on your project root choosing + // + // "Run As" --> "Maven generate-sources". + // + // This step is being required whenever changes to your model classes in ${package}.model happen. + + criteria.where(cb.equal( airlineRoot.get( Airline_.icaoCode), "DLH" )); + final List<Airline> airlines = em.createQuery( criteria ).getResultList(); + for (final Airline airline : airlines ) { + System.out.println(airline); + } + em.getTransaction().commit(); + log.info("Read completed"); + + em.close(); + + factory.close(); + } } \ No newline at end of file