--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<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">\r
+ <properties>\r
+ <hibernate.version>4.2.6.Final</hibernate.version>\r
+ <hibernate.entitymanager.version>4.2.6.Final</hibernate.entitymanager.version>\r
+ <hibernate.c3p0.version>4.2.6.Final</hibernate.c3p0.version>\r
+ <hibernate.validator.version>5.0.1.Final</hibernate.validator.version>\r
+ <hibernate.jpa20.version>1.0.1.Final</hibernate.jpa20.version>\r
+ <slf4j.version>1.4.2</slf4j.version>\r
+ </properties>\r
+ <modelVersion>4.0.0</modelVersion>\r
+ <groupId>de.test</groupId>\r
+ <artifactId>schemaexport-example</artifactId>\r
+ <packaging>pom</packaging>\r
+ <version>1.0-SNAPSHOT</version>\r
+ <name>Schemaexport Example</name>\r
+ <dependencyManagement>\r
+ <dependencies>\r
+ <dependency>\r
+ <groupId>org.hibernate</groupId>\r
+ <artifactId>hibernate-entitymanager</artifactId>\r
+ <version>${hibernate.entitymanager.version}</version>\r
+ <type>jar</type>\r
+ <exclusions>\r
+ <exclusion>\r
+ <groupId>commons-logging</groupId>\r
+ <artifactId>commons-logging</artifactId>\r
+ </exclusion>\r
+ </exclusions>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.hibernate</groupId>\r
+ <artifactId>hibernate-core</artifactId>\r
+ <version>${hibernate.version}</version>\r
+ <type>jar</type>\r
+ <exclusions>\r
+ <exclusion>\r
+ <groupId>commons-logging</groupId>\r
+ <artifactId>commons-logging</artifactId>\r
+ </exclusion>\r
+ </exclusions>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.hibernate</groupId>\r
+ <artifactId>hibernate-validator</artifactId>\r
+ <version>${hibernate.validator.version}</version>\r
+ <type>jar</type>\r
+ <exclusions>\r
+ <exclusion>\r
+ <groupId>commons-logging</groupId>\r
+ <artifactId>commons-logging</artifactId>\r
+ </exclusion>\r
+ </exclusions>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.hibernate.javax.persistence</groupId>\r
+ <artifactId>hibernate-jpa-2.0-api</artifactId>\r
+ <version>${hibernate.jpa20.version}</version>\r
+ <type>jar</type>\r
+ </dependency>\r
+ <dependency><!-- Logging per SLF4J auf Log4J -->\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-log4j12</artifactId>\r
+ <version>${slf4j.version}</version>\r
+ <type>jar</type>\r
+ </dependency>\r
+ <dependency><!-- Commons-Logging ueber SLF4J -->\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>jcl-over-slf4j</artifactId>\r
+ <version>${slf4j.version}</version>\r
+ <type>jar</type>\r
+ </dependency>\r
+ <dependency><!-- Commons-Logging -->\r
+ <groupId>commons-logging</groupId>\r
+ <artifactId>commons-logging</artifactId>\r
+ <version>1.0.4</version>\r
+ <type>jar</type>\r
+ </dependency>\r
+\r
+ <dependency>\r
+ <groupId>org.hsqldb</groupId>\r
+ <artifactId>hsqldb</artifactId>\r
+ <version>2.3.0</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>mysql</groupId>\r
+ <artifactId>mysql-connector-java</artifactId>\r
+ <version>5.1.6</version>\r
+ <type>jar</type>\r
+ </dependency>\r
+ </dependencies>\r
+ </dependencyManagement>\r
+ <build>\r
+ <pluginManagement>\r
+ <plugins>\r
+ <plugin>\r
+ <artifactId>maven-compiler-plugin</artifactId>\r
+ <configuration>\r
+ <source>1.6</source>\r
+ <target>1.6</target>\r
+ <encoding>UTF-8</encoding>\r
+ </configuration>\r
+ </plugin>\r
+ </plugins>\r
+ </pluginManagement>\r
+ </build>\r
+ <modules>\r
+ <module>schemaexport-example-domain</module>\r
+ <module>schemaexport-example-persistence-impl</module>\r
+ </modules>\r
+</project>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
+ <parent>\r
+ <groupId>de.test</groupId>\r
+ <artifactId>schemaexport-example</artifactId>\r
+ <version>1.0-SNAPSHOT</version>\r
+ </parent>\r
+ <modelVersion>4.0.0</modelVersion>\r
+ <artifactId>schemaexport-example-domain</artifactId>\r
+ <packaging>jar</packaging>\r
+ <version>1.0-SNAPSHOT</version>\r
+ <name>Schemaexport Example Domain</name>\r
+ <description>Domain Objects</description>\r
+ \r
+ <dependencies>\r
+ <dependency>\r
+ <groupId>org.hibernate.javax.persistence</groupId>\r
+ <artifactId>hibernate-jpa-2.0-api</artifactId>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.hibernate</groupId>\r
+ <artifactId>hibernate-validator</artifactId>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ </dependencies>\r
+ \r
+</project>\r
--- /dev/null
+package de.test.schemaexport.domain;\r
+\r
+import javax.persistence.Column;\r
+import javax.persistence.Entity;\r
+import javax.persistence.GeneratedValue;\r
+import javax.persistence.GenerationType;\r
+import javax.persistence.Id;\r
+import javax.persistence.Table;\r
+\r
+/**\r
+ * Abteilungsklasse (Generator-Beispielcode).\r
+ * \r
+ * copyright\r
+ *\r
+ */\r
+@Entity\r
+@Table(name = "ABTEILUNG")\r
+public class Department {\r
+\r
+ @Id\r
+ @Column(name = "OID")\r
+ @GeneratedValue(strategy = GenerationType.AUTO)\r
+ private long oid;\r
+ \r
+ @Column(name = "name", nullable = false)\r
+ private String name;\r
+\r
+ public long getOid() {\r
+ return oid;\r
+ }\r
+\r
+ public void setOid(long oid) {\r
+ this.oid = oid;\r
+ }\r
+\r
+ public String getName() {\r
+ return name;\r
+ }\r
+\r
+ public void setName(String name) {\r
+ this.name = name;\r
+ }\r
+ \r
+ \r
+ \r
+}\r
--- /dev/null
+package de.test.schemaexport.domain;\r
+\r
+import javax.persistence.CascadeType;\r
+import javax.persistence.Column;\r
+import javax.persistence.Entity;\r
+import javax.persistence.FetchType;\r
+import javax.persistence.GeneratedValue;\r
+import javax.persistence.GenerationType;\r
+import javax.persistence.Id;\r
+import javax.persistence.JoinColumn;\r
+import javax.persistence.ManyToOne;\r
+import javax.persistence.Table;\r
+\r
+\r
+\r
+import org.hibernate.validator.constraints.Length;\r
+\r
+@Entity\r
+@Table(name = "Employee")\r
+public class Employee {\r
+\r
+ @Id\r
+ @Column(name = "OID")\r
+ @GeneratedValue(strategy = GenerationType.AUTO)\r
+ private long oid;\r
+ \r
+ @Length(min = 4, max = 81)\r
+ @Column(name = "name", nullable = false)\r
+ private String name;\r
+ \r
+ @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)\r
+ @JoinColumn(name = "FK_department", nullable = true)\r
+ private Department department;\r
+\r
+ public long getOid() {\r
+ return oid;\r
+ }\r
+\r
+ public void setOid(long oid) {\r
+ this.oid = oid;\r
+ }\r
+\r
+ public String getName() {\r
+ return name;\r
+ }\r
+\r
+ public void setName(String name) {\r
+ this.name = name;\r
+ }\r
+\r
+ public Department getDepartment() {\r
+ return department;\r
+ }\r
+\r
+ public void setDepartment(Department department) {\r
+ this.department = department;\r
+ }\r
+ \r
+ \r
+}\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<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">\r
+ <parent>\r
+ <groupId>de.test</groupId>\r
+ <artifactId>schemaexport-example</artifactId>\r
+ <version>1.0-SNAPSHOT</version>\r
+ </parent>\r
+ <modelVersion>4.0.0</modelVersion>\r
+ <artifactId>schemaexport-example-persistence-impl</artifactId>\r
+ <packaging>jar</packaging>\r
+ <version>1.0-SNAPSHOT</version>\r
+ <name>Schemaexport Example Persistenz</name>\r
+ <dependencies>\r
+ <dependency>\r
+ <groupId>de.test</groupId>\r
+ <artifactId>schemaexport-example-domain</artifactId>\r
+ <version>1.0-SNAPSHOT</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.hibernate</groupId>\r
+ <artifactId>hibernate-entitymanager</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.hibernate</groupId>\r
+ <artifactId>hibernate-core</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.hibernate</groupId>\r
+ <artifactId>hibernate-validator</artifactId>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-log4j12</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>mysql</groupId>\r
+ <artifactId>mysql-connector-java</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.hsqldb</groupId>\r
+ <artifactId>hsqldb</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>junit</groupId>\r
+ <artifactId>junit</artifactId>\r
+ <version>4.6</version>\r
+ <scope>test</scope>\r
+ </dependency>\r
+ </dependencies>\r
+\r
+ <build>\r
+ <plugins>\r
+ <plugin>\r
+ <groupId>de.juplo</groupId>\r
+ <artifactId>hibernate4-maven-plugin</artifactId>\r
+ <version>@project.version@</version>\r
+ <configuration>\r
+ <target>SCRIPT</target>\r
+ <driverClassName>org.hsqldb.jdbcDriver</driverClassName>\r
+ <hibernateDialect>org.hibernate.dialect.HSQLDialect</hibernateDialect>\r
+ <!-- \r
+ <driverClassName>com.mysql.jdbc.Driver</driverClassName>\r
+ <hibernateDialect>org.hibernate.dialect.MySQLDialect</hibernateDialect>\r
+ -->\r
+ </configuration>\r
+ <executions>\r
+ <execution>\r
+ <goals>\r
+ <goal>export</goal>\r
+ </goals>\r
+ </execution>\r
+ </executions>\r
+ </plugin>\r
+ </plugins>\r
+ </build>\r
+</project>
\ No newline at end of file
--- /dev/null
+package de.test.schemaexport.persistence.dao;\r
+\r
+import javax.persistence.EntityManager;\r
+import de.test.schemaexport.domain.Department;\r
+\r
+public interface IDepartmentDAO {\r
+\r
+ Department findByID(EntityManager em, long id);\r
+\r
+ Department createOrUpdate(EntityManager em, Department toCreate);\r
+\r
+}\r
--- /dev/null
+package de.test.schemaexport.persistence.dao;\r
+\r
+import javax.persistence.EntityManager;\r
+\r
+import de.test.schemaexport.domain.Employee;\r
+\r
+public interface IEmployeeDAO {\r
+\r
+ Employee findByID(EntityManager em, long id);\r
+ \r
+ Employee createOrUpdate(EntityManager em, Employee toCreate);\r
+\r
+}\r
--- /dev/null
+package de.test.schemaexport.persistence.dao.impl;\r
+\r
+import javax.persistence.EntityManager;\r
+import de.test.schemaexport.domain.Department;\r
+import de.test.schemaexport.persistence.dao.IDepartmentDAO;\r
+\r
+public class DepartmentDAO implements IDepartmentDAO {\r
+\r
+ public Department findByID(EntityManager em, long id) {\r
+ return em.find(Department.class, id);\r
+ }\r
+\r
+ public Department createOrUpdate(EntityManager em, Department toCreateOrUpdate) {\r
+ return em.merge(toCreateOrUpdate);\r
+ }\r
+\r
+}\r
--- /dev/null
+package de.test.schemaexport.persistence.dao.impl;\r
+\r
+import javax.persistence.EntityManager;\r
+\r
+import de.test.schemaexport.domain.Employee;\r
+import de.test.schemaexport.persistence.dao.IEmployeeDAO;\r
+\r
+public class EmployeeDAO implements IEmployeeDAO {\r
+\r
+ public Employee findByID(EntityManager em, long id) {\r
+ return em.find(Employee.class, id);\r
+ }\r
+\r
+ public Employee createOrUpdate(EntityManager em, Employee toCreateOrUpdate) {\r
+ return em.merge(toCreateOrUpdate);\r
+ }\r
+\r
+ \r
+}\r
--- /dev/null
+<persistence version="1.0"\r
+ xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">\r
+ <persistence-unit name="swmtestappManagerTest">\r
+ <!-- in practice configured via Spring LocalContainerEntityManagerFactoryBean - packagesToScan -->\r
+ <class>de.test.schemaexport.domain.Department</class>\r
+ <class>de.test.schemaexport.domain.Employee</class>\r
+ <properties>\r
+ <property name="hibernate.hbm2ddl.auto" value="create-drop" />\r
+ <property name="hibernate.connection.username" value="sa" />\r
+ <property name="hibernate.connection.password" value="" />\r
+ <property name="hibernate.show_sql" value="true" />\r
+ <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />\r
+ <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />\r
+ <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:test"/>\r
+ </properties>\r
+ </persistence-unit>\r
+</persistence>\r
--- /dev/null
+package de.test.schemaexport.persistence.dao.impl;\r
+import javax.persistence.EntityManager;\r
+import javax.persistence.EntityManagerFactory;\r
+import javax.persistence.EntityTransaction;\r
+import javax.persistence.Persistence;\r
+\r
+import org.junit.After;\r
+import org.junit.AfterClass;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.BeforeClass;\r
+import org.junit.Ignore;\r
+import org.junit.Test;\r
+\r
+import de.test.schemaexport.domain.Department;\r
+\r
+public class DAOTest {\r
+ \r
+ private static EntityManagerFactory emf;\r
+ private EntityManager em;\r
+ private DepartmentDAO departmentDAO = new DepartmentDAO();\r
+ \r
+ @BeforeClass\r
+ public static void setUpClass() {\r
+ // Use persistence.xml configuration\r
+ emf = Persistence.createEntityManagerFactory("swmtestappManagerTest");\r
+ Assert.assertNotNull(emf);\r
+ }\r
+ \r
+ @Before\r
+ public void setUp() {\r
+ em = emf.createEntityManager(); // Retrieve an application managed entity manager\r
+ Assert.assertNotNull(em);\r
+ \r
+ EntityTransaction tx = em.getTransaction();\r
+ Assert.assertNotNull(tx);\r
+ \r
+ tx.begin();\r
+ tx.setRollbackOnly();\r
+ }\r
+ \r
+ @Test\r
+ public void testSomething() {\r
+ Department department = new Department();\r
+ department.setName("Dep");\r
+ Department result = departmentDAO.createOrUpdate(em, department);\r
+ System.out.println(result.getOid());\r
+ }\r
+ \r
+ @After\r
+ public void tearDown() {\r
+ em.getTransaction().rollback();\r
+ //em.getTransaction().commit();\r
+ em.close();\r
+ }\r
+ \r
+ @AfterClass\r
+ public static void tearDownClass() {\r
+\r
+ emf.close();\r
+ }\r
+ \r
+ \r
+}\r
--- /dev/null
+# Der Root-Logger hat den Level DEBUG\r
+log4j.rootLogger=WARN, A1\r
+\r
+# Wir haben einen Appender mit der Destionation Konsole\r
+log4j.appender.A1=org.apache.log4j.ConsoleAppender\r
+\r
+# F�r diesen Appender verwenden wir eine Layout\r
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout\r
+\r
+# Datum im ISO-Format ISO-8601 anzeigen\r
+log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n\r
+\r