Showing posts with label JPA. Show all posts
Showing posts with label JPA. Show all posts

Saturday, March 30, 2013

Maven JPA project with alternative JPA provider - persistence-eclipselink.xml and persiste-hibernate.xml

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

[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>

Sunday, February 20, 2011

Access JPA2 entitites using Servlet and Session EJB

Introduction to Oracle Enterprise Pack for Eclipse 11g JPA Workbench
http://www.oracle.com/technetwork/articles/cioroianu-eclipse-jpa-084626.html

1.create Eclipse Web project testWeb


2.create Servlet calling Session EJB
package dave;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class TestJPAServlet
*/
public class TestJPAServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public TestJPAServlet() {
super();
// TODO Auto-generated constructor stub
}


@EJB
SessionJPA2EJBRemote remoteBusinessIntf;


/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

String nameParam = request.getParameter("emp");

Author author = remoteBusinessIntf.findAuthorByName(nameParam);

System.out.println("author " + author);

PrintWriter out = response.getWriter();

out.println("author" + author);

// Books
Set<Book> books = author.getBooks();

for (Book book : books) {
System.out.println("book " + book);
out.println("book" + book);
}
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}




3. call servlet using URL composed of testWeb project and Servlet
http://localhost:7001/testWeb/TestJPAServlet?name=dave



[EL Finest]: 2011-02-20 15:15:14.763--ServerSession(10406216)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--End deploying Persistence Unit books; session file:/home/dave/workspace/wls1033/testJPA2/build/classes/_books; state Deployed; factoryCount 1
[EL Finer]: 2011-02-20 15:15:14.763--ServerSession(10406216)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--client acquired
[EL Finer]: 2011-02-20 15:15:14.763--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--TX binding to tx mgr, status=STATUS_ACTIVE
[EL Finest]: 2011-02-20 15:15:14.764--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Execute query ReadObjectQuery(referenceClass=Author sql="SELECT ID, NAME, INSERT_TIMESTAMP FROM AUTHOR WHERE (ID = ?)")
[EL Finest]: 2011-02-20 15:15:14.764--ServerSession(10406216)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--reconnecting to external connection pool
[EL Fine]: 2011-02-20 15:15:14.765--ServerSession(10406216)--Connection(3587614)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--SELECT ID, NAME, INSERT_TIMESTAMP FROM AUTHOR WHERE (ID = ?)
bind => [1]
[EL Finer]: 2011-02-20 15:15:14.767--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--TX beforeCompletion callback, status=STATUS_ACTIVE
[EL Finer]: 2011-02-20 15:15:14.767--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--begin unit of work commit
[EL Finer]: 2011-02-20 15:15:14.768--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--TX afterCompletion callback, status=COMMITTED
[EL Finer]: 2011-02-20 15:15:14.769--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--end unit of work commit
[EL Finer]: 2011-02-20 15:15:14.769--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--release unit of work
[EL Finer]: 2011-02-20 15:15:14.769--ClientSession(26961217)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--client released
author dave.Author@1fbc274
[EL Finest]: 2011-02-20 15:15:14.77--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Execute query ReadAllQuery(name="books" referenceClass=Book )
[EL Finest]: 2011-02-20 15:15:14.77--ServerSession(10406216)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--reconnecting to external connection pool
[EL Fine]: 2011-02-20 15:15:14.771--ServerSession(10406216)--Connection(11941411)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--SELECT ID, TITLE, COUNTER, INSERT_TIMESTAMP, AUTHOR_ID FROM BOOK WHERE (AUTHOR_ID = ?)
bind => [1]
[EL Finest]: 2011-02-20 15:15:14.773--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Execute query ReadObjectQuery(name="author" referenceClass=Author )
[EL Finest]: 2011-02-20 15:15:14.774--UnitOfWork(25911694)--Thread(Thread[[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Register the existing object dave.Book@9c71bf
book dave.Book@9c71bf

Create JPA2 Weblogic 10.3.4 project in Eclipse 3.6 (OEPE)

Oracle Enterprise Pack for Eclipse User Guide
http://download.oracle.com/docs/cd/E15315_07/help/oracle.eclipse.tools.common.doc/html/index.html
Object-Relational Mappings: Configuring the Persistence Provider for JPA Projects
http://download.oracle.com/docs/cd/E15315_07/help/oracle.eclipse.tools.orm.doc/html/files/libAndFacetForJPA.html

Introduction to Oracle Enterprise Pack for Eclipse 11g JPA Workbench
By Andrei Cioroianu
http://www.oracle.com/technetwork/articles/cioroianu-eclipse-jpa-084626.html

It is necessary to change PRE_CLASSPATH in WLS10.3.4 to enable JPA2.

1.configure Server Runtime for WLS 10.3.4
http://www.oracle.com/technetwork/developer-tools/eclipse/downloads/index.html

2.create JPA project




3.create test entity tables
CREATE TABLE  "AUTHOR" 
( "ID" NUMBER,
"NAME" VARCHAR2(255),
"INSERT_TIMESTAMP" TIMESTAMP (6) DEFAULT sysdate,
CONSTRAINT "AUTHOR_PK" PRIMARY KEY ("ID") ENABLE
)
/


CREATE OR REPLACE TRIGGER "BI_AUTHOR"
before insert on "AUTHOR"
for each row
begin
select "ID_GEN".nextval into :NEW.ID from dual;
end;

/
ALTER TRIGGER "BI_AUTHOR" ENABLE
/





CREATE TABLE  "BOOK" 
( "AUTHOR_ID" NUMBER NOT NULL ENABLE,
"TITLE" VARCHAR2(256),
"INSERT_TIMESTAMP" TIMESTAMP (6) DEFAULT sysdate,
"COUNTER" NUMBER(*,0),
"ID" NUMBER(*,0) NOT NULL ENABLE,
CONSTRAINT "ID" PRIMARY KEY ("ID") ENABLE,
CONSTRAINT "BOOK_AUTHOR" FOREIGN KEY ("AUTHOR_ID")
REFERENCES "AUTHOR" ("ID") ENABLE
)
/


CREATE OR REPLACE TRIGGER "BOOK_ID"
BEFORE
insert on "BOOK"
for each row
begin3
select "ID_GEN".nextval into :NEW.ID from dual;

end;
/
ALTER TRIGGER "BOOK_ID" ENABLE
/






4.generate JPA entities from tables










package dave;

import java.io.Serializable;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Set;


/**
* The persistent class for the AUTHOR database table.
*
*/
@Entity
public class Author implements Serializable {

private static final long serialVersionUID = 4224149688123855811L;

@Id
@SequenceGenerator(name="AUTHOR_ID_GENERATOR", sequenceName="ID_GEN")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="AUTHOR_ID_GENERATOR")
private long id;

@Column(name="INSERT_TIMESTAMP")
private Timestamp insertTimestamp;

private String name;

//bi-directional many-to-one association to Book
@OneToMany(mappedBy="author")
private Set<Book> books;

public Author() {
}

public long getId() {
return this.id;
}

public void setId(long id) {
this.id = id;
}

public Timestamp getInsertTimestamp() {
return this.insertTimestamp;
}

public void setInsertTimestamp(Timestamp insertTimestamp) {
this.insertTimestamp = insertTimestamp;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public Set<Book> getBooks() {
return this.books;
}

public void setBooks(Set<Book> books) {
this.books = books;
}

}

package dave;

import java.io.Serializable;
import javax.persistence.*;
import java.sql.Timestamp;
import java.math.BigDecimal;


/**
* The persistent class for the BOOK database table.
*
*/
@Entity
public class Book implements Serializable {

private static final long serialVersionUID = -9138882871442399233L;

@Id
@SequenceGenerator(name="BOOK_ID_GENERATOR", sequenceName="ID_GEN")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="BOOK_ID_GENERATOR")
private long id;

private BigDecimal counter;

@Column(name="INSERT_TIMESTAMP")
private Timestamp insertTimestamp;

private String title;

//bi-directional many-to-one association to Author
@ManyToOne
private Author author;

public Book() {
}

public long getId() {
return this.id;
}

public void setId(long id) {
this.id = id;
}

public BigDecimal getCounter() {
return this.counter;
}

public void setCounter(BigDecimal counter) {
this.counter = counter;
}

public Timestamp getInsertTimestamp() {
return this.insertTimestamp;
}

public void setInsertTimestamp(Timestamp insertTimestamp) {
this.insertTimestamp = insertTimestamp;
}

public String getTitle() {
return this.title;
}

public void setTitle(String title) {
this.title = title;
}

public Author getAuthor() {
return this.author;
}

public void setAuthor(Author author) {
this.author = author;
}

}




JPA tools Entity editor


edit persistence.xml file
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/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/persistence_2_0.xsd">
<persistence-unit name="books" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/XE</jta-data-source>
<class>dave.Book</class>
<class>dave.Author</class>
<shared-cache-mode>NONE</shared-cache-mode><!-- shared-cache-mode must
come after any class definitions (usually SE only) - the JPA schema is ordered -->
<properties>
<property name="eclipselink.target-server" value="WebLogic_10" />
<property name="eclipselink.target-database" value="Oracle" />
<property name="eclipselink.logging.level" value="FINEST" />
<!-- new for 10.3.4.0 http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging#Server_Logging -->
<property name="eclipselink.logging.logger" value="DefaultLogger" />
<!-- turn off DDL generation after the model is stable -->
<!-- property name="eclipselink.ddl-generation" value="drop-and-create-tables"/ -->
<!-- property name="eclipselink.ddl-generation.output-mode" value="database"/ -->
</properties>
</persistence-unit>
</persistence>




5. create Session EJB to access JPA entities

package dave;

import java.util.Set;

import javax.ejb.Stateless;
import javax.persistence.PersistenceContext;

import weblogic.javaee.CallByReference;

/**
* Session Bean implementation class SessionJPA2EJB
*/
@Stateless(mappedName = "SessionJPA2EJB")
@CallByReference
public class SessionJPA2EJB implements SessionJPA2EJBRemote, SessionJPA2EJBLocal {

/**
* Default constructor.
*/
public SessionJPA2EJB() {
// TODO Auto-generated constructor stub
}

@PersistenceContext
private javax.persistence.EntityManager books;

/* (non-Javadoc)
* @see dave.SessionJPA2Remote#findAuthor(long)
*/
@Override
public Author findAuthor(long authorId) {

Author author = books.find(Author.class, authorId);

System.out.println("author " + author);

//Books
Set<Book> books = author.getBooks();

for(Book book : books){
System.out.println("book " + book);
}

return author;
}

/* (non-Javadoc)
* @see dave.SessionJPA2Remote#findBook(long)
*/
@Override
public Book findBook(long bookId) {

Book book = books.find(Book.class, bookId);

System.out.println("book " + book);

if (book != null) {
Author author = book.getAuthor();

System.out.println("author " + author);
}

return book;
}


}




Initial loading of Persistence Unit in Weblogic
[EL Finest]: 2011-02-20 15:15:06.076--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Begin predeploying Persistence Unit books; session file:/home/dave/workspace/wls1033/testJPA2/build/classes/_books; state Initial; factoryCount 0
[EL Finest]: 2011-02-20 15:15:06.076--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--property=eclipselink.orm.throw.exceptions; default value=true
[EL Finest]: 2011-02-20 15:15:06.076--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--property=eclipselink.weaving.changetracking; default value=true
[EL Finest]: 2011-02-20 15:15:06.077--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--property=eclipselink.weaving.lazy; default value=true
[EL Finest]: 2011-02-20 15:15:06.077--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--property=eclipselink.weaving.eager; default value=false
[EL Finest]: 2011-02-20 15:15:06.077--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--property=eclipselink.weaving.fetchgroups; default value=true
[EL Finest]: 2011-02-20 15:15:06.077--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--property=eclipselink.weaving.internal; default value=true
[EL Finest]: 2011-02-20 15:15:06.078--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--property=eclipselink.jpa.uppercase-column-names; default value=false
[EL Finer]: 2011-02-20 15:15:06.078--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Searching for default mapping file in file:/home/dave/workspace/wls1033/testJPA2/build/classes/
[EL Finer]: 2011-02-20 15:15:06.079--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Searching for default mapping file in file:/home/dave/workspace/wls1033/testJPA2/build/classes/
[EL Config]: 2011-02-20 15:15:06.084--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--The access type for the persistent class [class dave.Author] is set to [FIELD].
[EL Config]: 2011-02-20 15:15:06.085--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--The target entity (reference) class for the one to many mapping element [field books] is being defaulted to: class dave.Book.
[EL Config]: 2011-02-20 15:15:06.086--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--The access type for the persistent class [class dave.Book] is set to [FIELD].
[EL Config]: 2011-02-20 15:15:06.086--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--The target entity (reference) class for the many to one mapping element [field author] is being defaulted to: class dave.Author.
[EL Config]: 2011-02-20 15:15:06.087--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--The alias name for the entity class [class dave.Author] is being defaulted to: Author.
[EL Config]: 2011-02-20 15:15:06.088--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--The table name for entity [class dave.Author] is being defaulted to: AUTHOR.
[EL Config]: 2011-02-20 15:15:06.088--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--The column name for element [field id] is being defaulted to: ID.
[EL Config]: 2011-02-20 15:15:06.088--ServerSession(10406216)--Thread(Thread[[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--The column name for element [field name] is being defaulted to: NAME.


Execution of JPA query
[EL Fine]: 2011-02-20 11:25:09.515--ServerSession(14527944)--Connection(16230875)--Thread(Thread[[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--SELECT ID, TITLE, COUNTER, INSERT_TIMESTAMP, AUTHOR_ID FROM BOOK WHERE (AUTHOR_ID = ?)
bind => [1]
[EL Finest]: 2011-02-20 11:25:09.516--UnitOfWork(20720277)--Thread(Thread[[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Execute query ReadObjectQuery(name="author" referenceClass=Author )
[EL Finest]: 2011-02-20 11:25:09.517--UnitOfWork(20720277)--Thread(Thread[[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Register the existing object dave.Book@1b09a99
book dave.Book@1b09a99
[EL Finer]: 2011-02-20 11:25:09.517--UnitOfWork(20720277)--Thread(Thread[[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--TX beforeCompletion callback, status=STATUS_ACTIVE
[EL Finer]: 2011-02-20 11:25:09.517--UnitOfWork(20720277)--Thread(Thread[[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--begin unit of work commit
[EL Finer]: 2011-02-20 11:25:09.518--UnitOfWork(20720277)--Thread(Thread[[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--TX afterCompletion callback, status=COMMITTED
[EL Finer]: 2011-02-20 11:25:09.519--UnitOfWork(20720277)--Thread(Thread[[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--end unit of work commit
[EL Finer]: 2011-02-20 11:25:09.519--UnitOfWork(20720277)--Thread(Thread[[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--release unit of work
[EL Finer]: 2011-02-20 11:25:09.519--ClientSession(24495389)--Thread(Thread[[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--client released
[EL Finer]: 2011-02-20 11:52:37.358--ServerSession(14527944)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--client acquired
[EL Finer]: 2011-02-20 11:52:37.358--UnitOfWork(953536)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--TX binding to tx mgr, status=STATUS_ACTIVE
[EL Finest]: 2011-02-20 11:52:37.359--UnitOfWork(953536)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Execute query ReadObjectQuery(referenceClass=Author sql="SELECT ID, NAME, INSERT_TIMESTAMP FROM AUTHOR WHERE (ID = ?)")
[EL Finest]: 2011-02-20 11:52:37.359--ServerSession(14527944)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--reconnecting to external connection pool
[EL Fine]: 2011-02-20 11:52:37.361--ServerSession(14527944)--Connection(20630989)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--SELECT ID, NAME, INSERT_TIMESTAMP FROM AUTHOR WHERE (ID = ?)
bind => [1]
author dave.Author@19d6908