We want to provide alternative persistence.xml files to test alternative JPA providers in same project
persistence-eclipselink.xml and persiste-hibernate.xml will be created
Use Maven archetype JPA project for start
http://www.mastertheboss.com/maven-hibernate-jpa/maven-and-jpa-tutorial
Create project from archetype
Files in created project
Run project with EclipseLink
Add hibernate dependency
Add profiles for alternative JPA providers
Inspired by Geronimo tests - use profiles for alternative JPA providers
http://svn.apache.org/repos/asf/geronimo/samples/tags/samples-parent-3.0-beta-1/samples/javaee6/jpa20demo-javaee6/jpa20demo-javaee6-war/
Maven dependency list
When run with -Peclipselink or -Phibernate following action is triggered
Dependencies can be optional based on profile
EclipseLink is set as active profile by default
This will allow to run alternative unit tests for different JPA providers
Modified pom.xml with dependencies inside profile
persistence-eclipselink.xml and persiste-hibernate.xml will be created
Use Maven archetype JPA project for start
http://www.mastertheboss.com/maven-hibernate-jpa/maven-and-jpa-tutorial
Create project from archetype
[dave@dave workspace]$ mvn archetype:generate -DarchetypeGroupId=com.github.lalyos -DarchetypeArtifactId=standalone-jpa-eclipselink-archetype -DgroupId=com.mastertheboss -DartifactId=EclipseJPAExample -Dversion=1.0-SNAPSHOT -Dpackage=com.mastertheboss -DinteractiveMode=false
/usr/java//jdk1.7.0_13
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] Archetype [com.github.lalyos:standalone-jpa-eclipselink-archetype:0.0.2] found in catalog remote
Downloading: http://repo.maven.apache.org/maven2/com/github/lalyos/standalone-jpa-eclipselink-archetype/0.0.2/standalone-jpa-eclipselink-archetype-0.0.2.jar
Downloaded: http://repo.maven.apache.org/maven2/com/github/lalyos/standalone-jpa-eclipselink-archetype/0.0.2/standalone-jpa-eclipselink-archetype-0.0.2.jar (5 KB at 6.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/com/github/lalyos/standalone-jpa-eclipselink-archetype/0.0.2/standalone-jpa-eclipselink-archetype-0.0.2.pom
Downloaded: http://repo.maven.apache.org/maven2/com/github/lalyos/standalone-jpa-eclipselink-archetype/0.0.2/standalone-jpa-eclipselink-archetype-0.0.2.pom (3 KB at 4.0 KB/sec)
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: standalone-jpa-eclipselink-archetype:0.0.2
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.mastertheboss
[INFO] Parameter: artifactId, Value: EclipseJPAExample
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.mastertheboss
[INFO] Parameter: packageInPathFormat, Value: com/mastertheboss
[INFO] Parameter: package, Value: com.mastertheboss
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: com.mastertheboss
[INFO] Parameter: artifactId, Value: EclipseJPAExample
[INFO] project created from Archetype in dir: /home/dave/workspace/EclipseJPAExample
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.438s
[INFO] Finished at: Sat Mar 30 07:52:16 CET 2013
[INFO] Final Memory: 8M/21M
[INFO] ------------------------------------------------------------------------
Files in created project
[dave@dave workspace]$ ls -lR EclipseJPAExample/
EclipseJPAExample/:
total 20
-rw-rw-r--. 1 dave dave 70 Mar 30 07:52 ij.properties
-rw-rw-r--. 1 dave dave 1206 Mar 30 07:52 pom.xml
-rw-rw-r--. 1 dave dave 69 Mar 30 07:52 run.sh
-rw-rw-r--. 1 dave dave 107 Mar 30 07:52 show-derby.sh
drwxrwxr-x. 3 dave dave 4096 Mar 30 07:52 src
EclipseJPAExample/src:
total 4
drwxrwxr-x. 4 dave dave 4096 Mar 30 07:52 main
EclipseJPAExample/src/main:
total 8
drwxrwxr-x. 3 dave dave 4096 Mar 30 07:52 java
drwxrwxr-x. 3 dave dave 4096 Mar 30 07:52 resources
EclipseJPAExample/src/main/java:
total 4
drwxrwxr-x. 3 dave dave 4096 Mar 30 07:52 com
EclipseJPAExample/src/main/java/com:
total 4
drwxrwxr-x. 4 dave dave 4096 Mar 30 07:52 mastertheboss
EclipseJPAExample/src/main/java/com/mastertheboss:
total 8
drwxrwxr-x. 2 dave dave 4096 Mar 30 07:52 domain
drwxrwxr-x. 2 dave dave 4096 Mar 30 07:52 jpa
EclipseJPAExample/src/main/java/com/mastertheboss/domain:
total 8
-rw-rw-r--. 1 dave dave 937 Mar 30 07:52 Department.java
-rw-rw-r--. 1 dave dave 1001 Mar 30 07:52 Employee.java
EclipseJPAExample/src/main/java/com/mastertheboss/jpa:
total 4
-rw-rw-r--. 1 dave dave 1624 Mar 30 07:52 JpaTest.java
EclipseJPAExample/src/main/resources:
total 4
drwxrwxr-x. 2 dave dave 4096 Mar 30 07:52 META-INF
EclipseJPAExample/src/main/resources/META-INF:
total 4
-rw-rw-r--. 1 dave dave 1229 Mar 30 07:52 persistence.xml
[dave@dave workspace]$
Run project with EclipseLink
[dave@dave EclipseJPAExample]$ mvn compile exec:java -Dexec.mainClass=com.mastertheboss.jpa.JpaTest
/usr/java//jdk1.7.0_13
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building EclipseJPAExample 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ EclipseJPAExample ---
[debug] execute contextualize
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ EclipseJPAExample ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ EclipseJPAExample >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ EclipseJPAExample <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ EclipseJPAExample ---
[EL Finest]: 2013-03-30 08:06:21.895--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Begin predeploying Persistence Unit persistenceUnit; session file:/home/dave/workspace/EclipseJPAExample/target/classes/_persistenceUnit; state Initial; factoryCount 0
[EL Finest]: 2013-03-30 08:06:21.92--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--property=eclipselink.orm.throw.exceptions; default value=true
[EL Finest]: 2013-03-30 08:06:21.956--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--property=eclipselink.jpa.uppercase-column-names; default value=false
[EL Finer]: 2013-03-30 08:06:21.957--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Searching for default mapping file in file:/home/dave/workspace/EclipseJPAExample/target/classes/
[EL Finer]: 2013-03-30 08:06:21.961--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Searching for default mapping file in file:/home/dave/workspace/EclipseJPAExample/target/classes/
[EL Config]: 2013-03-30 08:06:22.164--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The access type for the persistent class [class com.mastertheboss.domain.Employee] is set to [FIELD].
[EL Config]: 2013-03-30 08:06:22.235--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The target entity (reference) class for the many to one mapping element [field department] is being defaulted to: class com.mastertheboss.domain.Department.
[EL Config]: 2013-03-30 08:06:22.238--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The access type for the persistent class [class com.mastertheboss.domain.Department] is set to [FIELD].
[EL Config]: 2013-03-30 08:06:22.26--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The target entity (reference) class for the one to many mapping element [field employees] is being defaulted to: class com.mastertheboss.domain.Employee.
[EL Config]: 2013-03-30 08:06:22.261--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The alias name for the entity class [class com.mastertheboss.domain.Employee] is being defaulted to: Employee.
[EL Config]: 2013-03-30 08:06:22.266--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The table name for entity [class com.mastertheboss.domain.Employee] is being defaulted to: EMPLOYEE.
[EL Config]: 2013-03-30 08:06:22.298--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The column name for element [field id] is being defaulted to: ID.
[EL Config]: 2013-03-30 08:06:22.301--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The column name for element [field name] is being defaulted to: NAME.
[EL Config]: 2013-03-30 08:06:22.303--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The alias name for the entity class [class com.mastertheboss.domain.Department] is being defaulted to: Department.
[EL Config]: 2013-03-30 08:06:22.304--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The table name for entity [class com.mastertheboss.domain.Department] is being defaulted to: DEPARTMENT.
[EL Config]: 2013-03-30 08:06:22.309--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The column name for element [field id] is being defaulted to: ID.
[EL Config]: 2013-03-30 08:06:22.31--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The column name for element [field name] is being defaulted to: NAME.
[EL Config]: 2013-03-30 08:06:22.364--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The primary key column name for the mapping element [field department] is being defaulted to: ID.
[EL Config]: 2013-03-30 08:06:22.365--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The foreign key column name for the mapping element [field department] is being defaulted to: DEPARTMENT_ID.
[EL Finest]: 2013-03-30 08:06:22.418--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--End predeploying Persistence Unit persistenceUnit; session file:/home/dave/workspace/EclipseJPAExample/target/classes/_persistenceUnit; state Predeployed; factoryCount 0
[EL Finer]: 2013-03-30 08:06:22.419--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--JavaSECMPInitializer - transformer is null.
[EL Finest]: 2013-03-30 08:06:22.419--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Begin predeploying Persistence Unit persistenceUnit; session file:/home/dave/workspace/EclipseJPAExample/target/classes/_persistenceUnit; state Predeployed; factoryCount 0
[EL Finest]: 2013-03-30 08:06:22.419--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--End predeploying Persistence Unit persistenceUnit; session file:/home/dave/workspace/EclipseJPAExample/target/classes/_persistenceUnit; state Predeployed; factoryCount 1
[EL Finest]: 2013-03-30 08:06:22.425--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Begin deploying Persistence Unit persistenceUnit; session file:/home/dave/workspace/EclipseJPAExample/target/classes/_persistenceUnit; state Predeployed; factoryCount 1
[EL Finer]: 2013-03-30 08:06:22.454--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Could not initialize Validation Factory. Encountered following exception: java.lang.NoClassDefFoundError: javax/validation/Validation
[EL Finest]: 2013-03-30 08:06:22.467--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--property=eclipselink.logging.level; value=FINEST; translated value=FINEST
[EL Finest]: 2013-03-30 08:06:22.467--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--property=eclipselink.logging.level; value=FINEST; translated value=FINEST
[EL Finest]: 2013-03-30 08:06:22.468--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--property=javax.persistence.jdbc.user; value=EclipseJPAExample
[EL Finest]: 2013-03-30 08:06:22.468--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--property=javax.persistence.jdbc.password; value=xxxxxx
[EL Finest]: 2013-03-30 08:06:23.403--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--property=javax.persistence.jdbc.driver; value=org.apache.derby.jdbc.EmbeddedDriver
[EL Finest]: 2013-03-30 08:06:23.403--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--property=javax.persistence.jdbc.url; value=jdbc:derby:simpleDb;create=true
[EL Info]: 2013-03-30 08:06:23.404--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--EclipseLink, version: Eclipse Persistence Services - 2.2.1.v20110722-r9776
[EL Finest]: 2013-03-30 08:06:26.359--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--DBPlatform: org.eclipse.persistence.platform.database.HSQLPlatform, RegularExpression: (?i)hsql.*.
[EL Finest]: 2013-03-30 08:06:26.359--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--DBPlatform: org.eclipse.persistence.platform.database.InformixPlatform, RegularExpression: (?i)informix.*.
[EL Finest]: 2013-03-30 08:06:26.359--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--DBPlatform: org.eclipse.persistence.platform.database.PointBasePlatform, RegularExpression: (?i)pointbase.*.
[EL Finest]: 2013-03-30 08:06:26.36--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--DBPlatform: org.eclipse.persistence.platform.database.DB2Platform, RegularExpression: (?i).*db2.*.
[EL Finest]: 2013-03-30 08:06:26.36--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--DBPlatform: org.eclipse.persistence.platform.database.SQLServerPlatform, RegularExpression: (?i)microsoft.*.
[EL Finest]: 2013-03-30 08:06:26.36--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--DBPlatform: org.eclipse.persistence.platform.database.PostgreSQLPlatform, RegularExpression: (?i)postgresql.*.
[EL Finest]: 2013-03-30 08:06:26.36--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--DBPlatform: org.eclipse.persistence.platform.database.MaxDBPlatform, RegularExpression: SAP DB.
[EL Finest]: 2013-03-30 08:06:26.36--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--DBPlatform: org.eclipse.persistence.platform.database.H2Platform, RegularExpression: (?i)h2.*.
[EL Finest]: 2013-03-30 08:06:26.361--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--DBPlatform: org.eclipse.persistence.platform.database.SybasePlatform, RegularExpression: (?i)(sybase.*)|(adaptive server enterprise.*)|(SQL Server).
[EL Finest]: 2013-03-30 08:06:26.361--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--DBPlatform: org.eclipse.persistence.platform.database.FirebirdPlatform, RegularExpression: (?i)firebird.*.
[EL Finest]: 2013-03-30 08:06:26.361--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--DBPlatform: org.eclipse.persistence.platform.database.JavaDBPlatform, RegularExpression: (?i).*derby.
[EL Fine]: 2013-03-30 08:06:26.361--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Detected Vendor platform: org.eclipse.persistence.platform.database.JavaDBPlatform
[EL Config]: 2013-03-30 08:06:26.387--ServerSession(18985176)--Connection(30138829)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--connecting(DatabaseLogin(
platform=>JavaDBPlatform
user name=> "EclipseJPAExample"
datasource URL=> "jdbc:derby:simpleDb;create=true"
))
[EL Config]: 2013-03-30 08:06:26.394--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connected: jdbc:derby:simpleDb
User: EclipseJPAExample
Database: Apache Derby Version: 10.8.2.2 - (1181258)
Driver: Apache Derby Embedded JDBC Driver Version: 10.8.2.2 - (1181258)
[EL Finest]: 2013-03-30 08:06:26.395--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection acquired from connection pool [default].
[EL Finest]: 2013-03-30 08:06:26.395--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection released to connection pool [default].
[EL Finest]: 2013-03-30 08:06:26.428--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--sequencing connected, state is Preallocation_Transaction_NoAccessor_State
[EL Finest]: 2013-03-30 08:06:26.428--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--sequence SEQUENCE: preallocation size 50
[EL Finest]: 2013-03-30 08:06:26.428--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--sequence SEQ_GEN: preallocation size 50
[EL Info]: 2013-03-30 08:06:26.517--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--file:/home/dave/workspace/EclipseJPAExample/target/classes/_persistenceUnit login successful
[EL Finest]: 2013-03-30 08:06:26.555--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Execute query DataModifyQuery(sql="CREATE TABLE EMPLOYEE (ID BIGINT NOT NULL, NAME VARCHAR(255), DEPARTMENT_ID BIGINT, PRIMARY KEY (ID))")
[EL Finest]: 2013-03-30 08:06:26.557--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-30 08:06:26.557--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--CREATE TABLE EMPLOYEE (ID BIGINT NOT NULL, NAME VARCHAR(255), DEPARTMENT_ID BIGINT, PRIMARY KEY (ID))
[EL Fine]: 2013-03-30 08:06:27.223--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--VALUES(1)
[EL Finest]: 2013-03-30 08:06:27.366--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection released to connection pool [default].
[EL Warning]: 2013-03-30 08:06:27.367--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.1.v20110722-r9776): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Table/View 'EMPLOYEE' already exists in Schema 'ECLIPSEJPAEXAMPLE'.
Error Code: 30000
Call: CREATE TABLE EMPLOYEE (ID BIGINT NOT NULL, NAME VARCHAR(255), DEPARTMENT_ID BIGINT, PRIMARY KEY (ID))
Query: DataModifyQuery(sql="CREATE TABLE EMPLOYEE (ID BIGINT NOT NULL, NAME VARCHAR(255), DEPARTMENT_ID BIGINT, PRIMARY KEY (ID))")
[EL Finest]: 2013-03-30 08:06:27.369--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The table (EMPLOYEE) is already in the database, and wont be created.
[EL Finest]: 2013-03-30 08:06:27.37--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Execute query DataModifyQuery(sql="CREATE TABLE DEPARTMENT (ID BIGINT NOT NULL, NAME VARCHAR(255), PRIMARY KEY (ID))")
[EL Finest]: 2013-03-30 08:06:27.37--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-30 08:06:27.37--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--CREATE TABLE DEPARTMENT (ID BIGINT NOT NULL, NAME VARCHAR(255), PRIMARY KEY (ID))
[EL Fine]: 2013-03-30 08:06:27.587--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--VALUES(1)
[EL Finest]: 2013-03-30 08:06:27.588--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection released to connection pool [default].
[EL Warning]: 2013-03-30 08:06:27.588--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.1.v20110722-r9776): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Table/View 'DEPARTMENT' already exists in Schema 'ECLIPSEJPAEXAMPLE'.
Error Code: 30000
Call: CREATE TABLE DEPARTMENT (ID BIGINT NOT NULL, NAME VARCHAR(255), PRIMARY KEY (ID))
Query: DataModifyQuery(sql="CREATE TABLE DEPARTMENT (ID BIGINT NOT NULL, NAME VARCHAR(255), PRIMARY KEY (ID))")
[EL Finest]: 2013-03-30 08:06:27.589--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--The table (DEPARTMENT) is already in the database, and wont be created.
[EL Finest]: 2013-03-30 08:06:27.59--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Execute query DataModifyQuery(sql="ALTER TABLE EMPLOYEE ADD CONSTRAINT MPLOYEEDPARTMENTID FOREIGN KEY (DEPARTMENT_ID) REFERENCES DEPARTMENT (ID)")
[EL Finest]: 2013-03-30 08:06:27.59--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-30 08:06:27.59--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--ALTER TABLE EMPLOYEE ADD CONSTRAINT MPLOYEEDPARTMENTID FOREIGN KEY (DEPARTMENT_ID) REFERENCES DEPARTMENT (ID)
[EL Fine]: 2013-03-30 08:06:27.709--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--VALUES(1)
[EL Finest]: 2013-03-30 08:06:27.711--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection released to connection pool [default].
[EL Warning]: 2013-03-30 08:06:27.711--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.1.v20110722-r9776): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Constraint 'MPLOYEEDPARTMENTID' already exists in Schema 'ECLIPSEJPAEXAMPLE'.
Error Code: 30000
Call: ALTER TABLE EMPLOYEE ADD CONSTRAINT MPLOYEEDPARTMENTID FOREIGN KEY (DEPARTMENT_ID) REFERENCES DEPARTMENT (ID)
Query: DataModifyQuery(sql="ALTER TABLE EMPLOYEE ADD CONSTRAINT MPLOYEEDPARTMENTID FOREIGN KEY (DEPARTMENT_ID) REFERENCES DEPARTMENT (ID)")
[EL Finest]: 2013-03-30 08:06:27.713--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Execute query DataModifyQuery(sql="CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME))")
[EL Finest]: 2013-03-30 08:06:27.714--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-30 08:06:27.714--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME))
[EL Fine]: 2013-03-30 08:06:27.853--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--VALUES(1)
[EL Finest]: 2013-03-30 08:06:27.854--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection released to connection pool [default].
[EL Warning]: 2013-03-30 08:06:27.855--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.1.v20110722-r9776): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Table/View 'SEQUENCE' already exists in Schema 'ECLIPSEJPAEXAMPLE'.
Error Code: 30000
Call: CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME))
Query: DataModifyQuery(sql="CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME))")
[EL Finest]: 2013-03-30 08:06:27.856--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Execute query DataReadQuery(sql="SELECT * FROM SEQUENCE WHERE SEQ_NAME = 'SEQ_GEN'")
[EL Finest]: 2013-03-30 08:06:27.857--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-30 08:06:27.857--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--SELECT * FROM SEQUENCE WHERE SEQ_NAME = SEQ_GEN
[EL Finest]: 2013-03-30 08:06:27.933--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection released to connection pool [default].
[EL Finer]: 2013-03-30 08:06:27.96--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Canonical Metamodel class [com.mastertheboss.domain.Department_] not found during initialization.
[EL Finer]: 2013-03-30 08:06:27.96--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Canonical Metamodel class [com.mastertheboss.domain.Employee_] not found during initialization.
[EL Finest]: 2013-03-30 08:06:27.96--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--End deploying Persistence Unit persistenceUnit; session file:/home/dave/workspace/EclipseJPAExample/target/classes/_persistenceUnit; state Deployed; factoryCount 1
[EL Finer]: 2013-03-30 08:06:27.991--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--client acquired: 7982406
[EL Finer]: 2013-03-30 08:06:28.031--ClientSession(7982406)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--acquire unit of work: 13165575
[EL Finer]: 2013-03-30 08:06:28.565--UnitOfWork(13165575)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--begin unit of work flush
[EL Finer]: 2013-03-30 08:06:28.568--UnitOfWork(13165575)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--end unit of work flush
[EL Finest]: 2013-03-30 08:06:28.568--UnitOfWork(13165575)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Execute query ReadAllQuery(referenceClass=Employee sql="SELECT ID, NAME, DEPARTMENT_ID FROM EMPLOYEE")
[EL Finest]: 2013-03-30 08:06:28.571--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-30 08:06:28.571--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--SELECT ID, NAME, DEPARTMENT_ID FROM EMPLOYEE
[EL Finest]: 2013-03-30 08:06:28.584--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection released to connection pool [default].
[EL Finest]: 2013-03-30 08:06:28.593--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Execute query ReadObjectQuery(name="department" referenceClass=Department )
[EL Finest]: 2013-03-30 08:06:28.594--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-30 08:06:28.594--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--SELECT ID, NAME FROM DEPARTMENT WHERE (ID = ?)
bind => [1]
[EL Finest]: 2013-03-30 08:06:28.613--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection released to connection pool [default].
[EL Finest]: 2013-03-30 08:06:28.62--UnitOfWork(13165575)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Register the existing object com.mastertheboss.domain.Department@94fb9d
[EL Finest]: 2013-03-30 08:06:28.623--ServerSession(18985176)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Execute query ReadObjectQuery(name="department" referenceClass=Department )
[EL Finest]: 2013-03-30 08:06:28.623--UnitOfWork(13165575)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Register the existing object com.mastertheboss.domain.Department@94fb9d
[EL Finer]: 2013-03-30 08:06:28.624--UnitOfWork(13165575)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--begin unit of work commit
[EL Finer]: 2013-03-30 08:06:28.627--UnitOfWork(13165575)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--end unit of work commit
[EL Finer]: 2013-03-30 08:06:28.627--UnitOfWork(13165575)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--resume unit of work
[EL Finest]: 2013-03-30 08:06:28.628--UnitOfWork(13165575)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Execute query ReadAllQuery(referenceClass=Employee sql="SELECT ID, NAME, DEPARTMENT_ID FROM EMPLOYEE")
[EL Finest]: 2013-03-30 08:06:28.628--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection acquired from connection pool [default].
[EL Fine]: 2013-03-30 08:06:28.628--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--SELECT ID, NAME, DEPARTMENT_ID FROM EMPLOYEE
[EL Finest]: 2013-03-30 08:06:28.629--ServerSession(18985176)--Connection(5592751)--Thread(Thread[com.mastertheboss.jpa.JpaTest.main(),5,com.mastertheboss.jpa.JpaTest])--Connection released to connection pool [default].
num of employess:2
next employee: Employee [id=3, name=Captain Nemo, department=java]
next employee: Employee [id=2, name=Jakab Gipsz, department=java]
.. done
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.653s
[INFO] Finished at: Sat Mar 30 08:06:28 CET 2013
[INFO] Final Memory: 20M/48M
[INFO] ------------------------------------------------------------------------
[dave@dave EclipseJPAExample]$
Add hibernate dependency
<?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>
<groupId>com.mastertheboss</groupId>
<artifactId>EclipseJPAExample</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>EclipseLink Repo</id>
<url>http://download.eclipse.org/rt/eclipselink/maven.repo</url>
<name>EclipseLink Repo</name>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.8.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbytools</artifactId>
<version>10.8.2.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.0.1.Final</version>
</dependency>
</dependencies>
</project>
Add profiles for alternative JPA providers
Inspired by Geronimo tests - use profiles for alternative JPA providers
http://svn.apache.org/repos/asf/geronimo/samples/tags/samples-parent-3.0-beta-1/samples/javaee6/jpa20demo-javaee6/jpa20demo-javaee6-war/
<profiles>
<profile>
<id>openjpa</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<id>rename-persistence-file</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Rename persistence-openjpa.xml to persistence.xml</echo>
<copy file="${basedir}/src/main/resources/META-INF/persistence_openjpa.xml" tofile="${project.build.directory}/${pom.artifactId}-${version}/WEB-INF/classes/META-INF/persistence.xml" overwrite="true" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>hibernate</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>JPAProvider</name>
<value>hibernate</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<id>rename-persistence-file</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
nfiguration>
<tasks>
<echo>Rename persistence-hibernate.xml to persistence.xml</echo>
<copy file="${basedir}/src/main/resources/META-INF/persistence_hibernate.xml" tofile="${project.build.directory}/${pom.artifactId}-${version}/WEB-INF/classes/META-INF/persistence.xml" overwrite="true" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>eclipselink</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>JPAProvider</name>
<value>eclipselink</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<id>rename-persistence-file</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Rename persistence-eclipselink.xml to persistence.xml</echo>
<copy file="${basedir}/src/main/resources/META-INF/persistence_eclipselink.xml" tofile="${project.build.directory}/${pom.artifactId}-${version}/WEB-INF/classes/META-INF/persistence.xml" overwrite="true" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Maven dependency list
[dave@dave EclipseJPAExample]$ mvn dependency::list
/usr/java//jdk1.7.0_13
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building EclipseJPAExample 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:list (default-cli) @ EclipseJPAExample ---
[INFO]
[INFO] The following files have been resolved:
[INFO] antlr:antlr:jar:2.7.7:compile
[INFO] commons-collections:commons-collections:jar:3.2.1:compile
[INFO] dom4j:dom4j:jar:1.6.1:compile
[INFO] org.apache.derby:derby:jar:10.8.2.2:compile
[INFO] org.apache.derby:derbytools:jar:10.8.2.2:compile
[INFO] org.eclipse.persistence:eclipselink:jar:2.2.1:compile
[INFO] org.eclipse.persistence:javax.persistence:jar:2.0.3:compile
[INFO] org.hibernate:hibernate-core:jar:4.0.1.Final:compile
[INFO] org.hibernate:hibernate-entitymanager:jar:4.0.1.Final:compile
[INFO] org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] org.javassist:javassist:jar:3.15.0-GA:compile
[INFO] org.jboss.logging:jboss-logging:jar:3.1.0.CR2:compile
[INFO] org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
[INFO] xml-apis:xml-apis:jar:1.0.b2:compile
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.760s
[INFO] Finished at: Sat Mar 30 08:35:54 CET 2013
[INFO] Final Memory: 6M/15M
[INFO] ------------------------------------------------------------------------
[dave@dave EclipseJPAExample]$
Create alternative persistence.xml files [dave@dave EclipseJPAExample]$ ls -l ./src/main/resources/META-INF
total 8
-rw-rw-r--. 1 dave dave 1230 Mar 30 08:06 persistence-eclipselink.xml
-rw-rw-r--. 1 dave dave 1067 Mar 30 08:19 persistence-hibernate.xml
[dave@dave EclipseJPAExample]$ more ./src/main/resources/META-INF/persistence-eclipselink.xml
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persiste
nce/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<!-- shouldn't be valid for java SE per specification, but it works for EclipseLink ..
. -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.Em
beddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:simpleDb;create=
true" />
<property name="javax.persistence.jdbc.user" value="EclipseJPAExample" />
<property name="javax.persistence.jdbc.password" value="EclipseJPAExample" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.logging.level" value="FINEST"/>
</properties>
</persistence-unit>
</persistence>
[dave@dave EclipseJPAExample]$ more ./src/main/resources/META-INF/persistence-hibernate.xml<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/pers
istence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.mastertheboss.domain.Employee</class>
<class>com.mastertheboss.domain.Department</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDri
ver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:simpleDb;create=true" />
<property name="javax.persistence.jdbc.user" value="EclipseJPAExample" />
<property name="javax.persistence.jdbc.password" value="EclipseJPAExample" />
<property name="hbm2ddl.auto" value="create" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
Run project with Hibernate as JPA provider [dave@dave EclipseJPAExample]$ mvn compile exec:java -Dexec.mainClass=com.mastertheboss.jpa.JpaTest
/usr/java//jdk1.7.0_13
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building EclipseJPAExample 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ EclipseJPAExample ---
[debug] execute contextualize
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ EclipseJPAExample ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ EclipseJPAExample >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ EclipseJPAExample <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ EclipseJPAExample ---
Mar 30, 2013 8:48:53 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Mar 30, 2013 8:48:53 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.0.1.Final}
Mar 30, 2013 8:48:53 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Mar 30, 2013 8:48:53 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Mar 30, 2013 8:48:54 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Mar 30, 2013 8:48:54 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
Mar 30, 2013 8:48:54 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
Mar 30, 2013 8:48:54 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [org.apache.derby.jdbc.EmbeddedDriver] at URL [jdbc:derby:simpleDb;create=true]
Mar 30, 2013 8:48:54 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=EclipseJPAExample, password=****, autocommit=true, release_mode=auto}
Mar 30, 2013 8:48:56 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.DerbyDialect
Mar 30, 2013 8:48:56 AM org.hibernate.dialect.DerbyDialect <init>
WARN: HHH000430: The DerbyDialect dialect has been deprecated; use one of the version-specific dialects instead
Mar 30, 2013 8:48:56 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
Mar 30, 2013 8:48:56 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate:
select
employee0_.id as id0_,
employee0_.department_id as department3_0_,
employee0_.name as name0_
from
Employee employee0_
Hibernate:
select
department0_.id as id1_0_,
department0_.name as name1_0_
from
Department department0_
where
department0_.id=?
Hibernate:
select
employee0_.id as id0_,
employee0_.department_id as department3_0_,
employee0_.name as name0_
from
Employee employee0_
num of employess:2
next employee: Employee [id=3, name=Captain Nemo, department=java]
next employee: Employee [id=2, name=Jakab Gipsz, department=java]
.. done
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.995s
[INFO] Finished at: Sat Mar 30 08:48:57 CET 2013
[INFO] Final Memory: 10M/24M
[INFO] ------------------------------------------------------------------------
[dave@dave EclipseJPAExample]$
Add profiles for persistence providers into pom.xml <profile>
<id>eclipselink</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>JPAProvider</name>
<value>eclipselink</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<id>rename-persistence-file</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Rename persistence-eclipselink.xml to persistence.xml</echo>
<copy file="${basedir}/src/main/resources/META-INF/persistence-eclipselink.xml" tofile="${project.build.directory}/classes/META-INF/persistence.xml" overwrite="true" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
When run with -Peclipselink or -Phibernate following action is triggered
[INFO] Executing tasks
[echo] Rename persistence-eclipselink.xml to persistence.xml
[copy] Copying 1 file to /home/dave/workspace/EclipseJPAExample/target/classes/META-INF
Dependencies can be optional based on profile
EclipseLink is set as active profile by default
This will allow to run alternative unit tests for different JPA providers
[dave@dave EclipseJPAExample]$ mvn dependency::list
/usr/java//jdk1.7.0_13
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building EclipseJPAExample 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:list (default-cli) @ EclipseJPAExample ---
[INFO]
[INFO] The following files have been resolved:
[INFO] org.apache.derby:derby:jar:10.8.2.2:compile
[INFO] org.apache.derby:derbytools:jar:10.8.2.2:compile
[INFO] org.eclipse.persistence:eclipselink:jar:2.2.1:compile
[INFO] org.eclipse.persistence:javax.persistence:jar:2.0.3:compile
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.506s
[INFO] Finished at: Sat Mar 30 09:23:06 CET 2013
[INFO] Final Memory: 6M/15M
[INFO] ------------------------------------------------------------------------
[dave@dave EclipseJPAExample]$ mvn dependency::list -Phibernate
/usr/java//jdk1.7.0_13
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building EclipseJPAExample 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:list (default-cli) @ EclipseJPAExample ---
[INFO]
[INFO] The following files have been resolved:
[INFO] antlr:antlr:jar:2.7.7:compile
[INFO] commons-collections:commons-collections:jar:3.2.1:compile
[INFO] dom4j:dom4j:jar:1.6.1:compile
[INFO] org.apache.derby:derby:jar:10.8.2.2:compile
[INFO] org.apache.derby:derbytools:jar:10.8.2.2:compile
[INFO] org.hibernate:hibernate-core:jar:4.0.1.Final:compile
[INFO] org.hibernate:hibernate-entitymanager:jar:4.0.1.Final:compile
[INFO] org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] org.javassist:javassist:jar:3.15.0-GA:compile
[INFO] org.jboss.logging:jboss-logging:jar:3.1.0.CR2:compile
[INFO] org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
[INFO] xml-apis:xml-apis:jar:1.0.b2:compile
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.562s
[INFO] Finished at: Sat Mar 30 09:23:22 CET 2013
[INFO] Final Memory: 6M/15M
[INFO] ------------------------------
Modified pom.xml with dependencies inside profile
<profiles>
<profile>
<id>hibernate</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>JPAProvider</name>
<value>hibernate</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.0.1.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<id>rename-persistence-file</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Rename persistence-hibernate.xml to persistence.xml</echo>
<copy file="${basedir}/src/main/resources/META-INF/persistence-hibernate.xml" tofile="${project.build.directory}/classes/META-INF/persistence.xml" overwrite="true" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>