Java EE integra una librería que ayuda al programador en java, en el manejo de datos que deben ir a una base de datos, pero existe un detalle en este dilema, por un lado tradicionalmente los datos se reflejan en un diseño en una Base de datos por medio de un diagrama Entidad-Relación, y por otro lado, desde el punto de vista de programación java, estos datos estan contenidos y representados en clases, y las classes no siguen las mismas reglas y/o formato que las Entidades en la Base de datos, entonces hablamos de un tradicional problema de impedancia en la representación de los datos, ya que por un lado, en java, las classes tienen capacidades funcionales de manejo dinámico de comportamiento de las clases, que no tiene mucho enfasis en los datos que contiene la clase y que se desean persistir o sea guardar en la base de datos, y por el lado de la base de datos, las entidades que representan los datos almacenados. Asi que por lo general se debe de hacer una interfaz entre las clases de java y las entidades de la base de datos, esto se hace haciendo una capa de interfaz con programación java entre las clases java y las tablas de la base de datos, implementando esto con alguna herramienta que hable java-base da datos, como puede ser JDBC. esto implica tambien programar una serie de utilidades que controlen concurrencia, bloqueo... de los datos. Todo esto se puede eliminar haciendo uso de la librería de java JPA (Java Persistence API) que contempla muchas de las operaciones requeridad en el proceso de guardar, recuperar, actualizar datos de la base de datos. Estas operaciones no son pocas, ni sencillas de controlar, sobre todo cuando se tienen entidades relacionadas a varios niveles, ya que para esto existen varias estrategías de control con sus pros y contras, que se dejan para otro apartado.
Para empezar se suguiere asimilar los conceptos de JPA que se describen sintetizados en el manual de especificación de Java EE que se puede encontrar en el portal de oracle. aquí se tomas 20 páginas para describirlo.
Posteriormente un documento que amplía estos conceptos es su propia especificación JSR 338 (java specification request) tambien del portal de oracle se obtiene. este documento es de 570 páginas.
Para más información
Java Persistence 2.1 API specification:
http://jcp.org/en/jsr/detail?id=338
■ EclipseLink, the Java Persistence API implementation in GlassFish Server:
http://www.eclipse.org/eclipselink/jpa.php
■ EclipseLink team blog:
http://eclipselink.blogspot.com/
■ EclipseLink wiki documentation:
http://wiki.eclipse.org/EclipseLink
Adicionalmente a estas especificaciones están las implementaciones de esta especificacion, estas son el software o librerías que se pueden descargar, entre estas estan ElicpseLink, TopLink, Hibernate, Apache OpenJPA, etc. entre ellos existe una permanente competencia por agregar servicios de persistencia que van más alla de la especificacion estandar JSR 338, como son MOXy, EIS, SDO, DBWS etc y algunas variantes de conceptos. Por ejemplo Hibernate ofrece varios servicios y formas adicionales, PERO la escencia de la persistencia de datos esta en la especificación, esto hace que sea independiente a cambios en tecnología o implementaciones que hagan caducar estas implementaciones adicionales y dejar fuera a la aplicación desarrollada.
jueves, 27 de abril de 2017
domingo, 16 de abril de 2017
Laboratorio JPA 2.0 EclipseLink Employee model with Oracle DB
Este laboratorio ejemplo se obtiene del link http://wiki.eclipse.org/EclipseLink/Examples/JPA/2.0/Employee
Se ejecuta en Netbeans, y se hace una configuración previa en la base de datos oracle, creando un usuario develop y sus tablespace etc...
Se hacen ajustes en pesistence.xml y se crea un a conneción a la base de datos oracle
En este ejemplo de eclipselink en el archivo persistence.xml que configura la persistence unit, se observa la inclusión a este archivo de las entity classes que se reflejaran posteriormente en tablas en la base de datos.
El projecto contiene tres archivos java transactions, queries, populate la que manda a llamar el projecto es transactions que crea la entityManager, y hace transacciones usando persist, merge, con variante pesimistlocking y una actualización.
En queries.java se llama a populate que pobla las tablas que se crearon con datos con lógica según la estructura y despues hace varios queries como ejemplo haciendo uso de CriteriaBuilder, QueryByExample.
El projecto en Netbeans se ve así
La construcción de las tablas en base de datos quedan así
La ejecución no da:
run:
[EL Config]: metadata: The access type for the persistent class [class model.Employee] is set to [FIELD].
[EL Config]: metadata: The target entity (reference) class for the one to one mapping element [field address] is being defaulted to: class model.Address.
[EL Config]: metadata: The target entity (reference) class for the many to many mapping element [field projects] is being defaulted to: class model.Project.
[EL Config]: metadata: The target entity (reference) class for the many to one mapping element [field manager] is being defaulted to: class model.Employee.
[EL Config]: metadata: The target entity (reference) class for the many to one mapping element [field jobTitle] is being defaulted to: class model.JobTitle.
[EL Config]: metadata: The target entity (reference) class for the one to many mapping element [field managedEmployees] is being defaulted to: class model.Employee.
[EL Config]: metadata: The target entity (reference) class for the one to many mapping element [field phoneNumbers] is being defaulted to: class model.PhoneNumber.
[EL Config]: metadata: The target entity (reference) class for the one to many mapping element [field degrees] is being defaulted to: class model.Degree.
[EL Config]: metadata: The target class (reference) class for the element collection mapping element [field responsibilities] is being defaulted to: class java.lang.String.
[EL Config]: metadata: The target class (reference) class for the element collection mapping element [field emailAddresses] is being defaulted to: class model.EmailAddress.
[EL Config]: metadata: The access type for the persistent class [class model.Degree] is set to [FIELD].
[EL Config]: metadata: The access type for the persistent class [class model.Project] is set to [FIELD].
[EL Config]: metadata: The target entity (reference) class for the many to one mapping element [field teamLeader] is being defaulted to: class model.Employee.
[EL Config]: metadata: The access type for the persistent class [class model.SmallProject] is set to [FIELD].
[EL Config]: metadata: The access type for the persistent class [class model.Address] is set to [FIELD].
[EL Config]: metadata: The access type for the persistent class [class model.PhoneNumber] is set to [FIELD].
[EL Config]: metadata: The element [field owner] is being defaulted to a one to one mapping.
[EL Config]: metadata: The target entity (reference) class for the many to one mapping element [field owner] is being defaulted to: class model.Employee.
[EL Config]: metadata: The access type for the persistent class [class model.JobTitle] is set to [FIELD].
[EL Config]: metadata: The access type for the persistent class [class model.LargeProject] is set to [FIELD].
[EL Config]: metadata: The access type for the persistent class [class model.EmploymentPeriod] is set to [FIELD].
[EL Config]: metadata: The access type for the persistent class [class model.EmailAddress] is set to [FIELD].
[EL Config]: metadata: The alias name for the entity class [class model.Employee] is being defaulted to: Employee.
[EL Config]: metadata: The table name for entity [class model.Employee] is being defaulted to: EMPLOYEE.
[EL Config]: metadata: The column name for element [endDate] is being defaulted to: ENDDATE.
[EL Config]: metadata: The column name for element [startDate] is being defaulted to: STARTDATE.
[EL Config]: metadata: The column name for element [salary] is being defaulted to: SALARY.
[EL Config]: metadata: The column name for element [version] is being defaulted to: VERSION.
[EL Config]: metadata: The secondary table primary key column name for element [class model.Employee] is being defaulted to: EMP_ID.
[EL Config]: metadata: The secondary table foreign key column name for element [model.Employee] is being defaulted to: EMP_ID.
[EL Config]: metadata: The alias name for the entity class [class model.Degree] is being defaulted to: Degree.
[EL Config]: metadata: The table name for entity [class model.Degree] is being defaulted to: DEGREE.
[EL Config]: metadata: The column name for element [name] is being defaulted to: NAME.
[EL Config]: metadata: The alias name for the entity class [class model.SmallProject] is being defaulted to: SmallProject.
[EL Config]: metadata: The alias name for the entity class [class model.Project] is being defaulted to: Project.
[EL Config]: metadata: The table name for entity [class model.Project] is being defaulted to: PROJECT.
[EL Config]: metadata: The column name for element [version] is being defaulted to: VERSION.
[EL Config]: metadata: The primary key column name for the inheritance class [class model.SmallProject] is being defaulted to: PROJ_ID.
[EL Config]: metadata: The foreign key column name for the inheritance class [model.SmallProject] is being defaulted to: PROJ_ID.
[EL Config]: metadata: The alias name for the entity class [class model.Address] is being defaulted to: Address.
[EL Config]: metadata: The table name for entity [class model.Address] is being defaulted to: ADDRESS.
[EL Config]: metadata: The column name for element [country] is being defaulted to: COUNTRY.
[EL Config]: metadata: The column name for element [province] is being defaulted to: PROVINCE.
[EL Config]: metadata: The column name for element [city] is being defaulted to: CITY.
[EL Config]: metadata: The column name for element [street] is being defaulted to: STREET.
[EL Config]: metadata: The alias name for the entity class [class model.PhoneNumber] is being defaulted to: PhoneNumber.
[EL Config]: metadata: The column name for element [type] is being defaulted to: TYPE.
[EL Config]: metadata: The alias name for the entity class [class model.JobTitle] is being defaulted to: JobTitle.
[EL Config]: metadata: The table name for entity [class model.JobTitle] is being defaulted to: JOBTITLE.
[EL Config]: metadata: The column name for element [title] is being defaulted to: TITLE.
[EL Config]: metadata: The alias name for the entity class [class model.LargeProject] is being defaulted to: LargeProject.
[EL Config]: metadata: The primary key column name for the inheritance class [class model.LargeProject] is being defaulted to: PROJ_ID.
[EL Config]: metadata: The foreign key column name for the inheritance class [model.LargeProject] is being defaulted to: PROJ_ID.
[EL Config]: metadata: The column name for element [milestone] is being defaulted to: MILESTONE.
[EL Config]: metadata: The column name for element [budget] is being defaulted to: BUDGET.
[EL Config]: metadata: The primary key column name for the mapping element [field owner] is being defaulted to: EMP_ID.
[EL Config]: metadata: The primary key column name for the mapping element [field responsibilities] is being defaulted to: EMP_ID.
[EL Config]: metadata: The primary key column name for the mapping element [field address] is being defaulted to: ADDRESS_ID.
[EL Config]: metadata: The source primary key column name for the many to many mapping [field projects] is being defaulted to: EMP_ID.
[EL Config]: metadata: The target primary key column name for the many to many mapping [field projects] is being defaulted to: PROJ_ID.
[EL Config]: metadata: The primary key column name for the mapping element [field manager] is being defaulted to: EMP_ID.
[EL Config]: metadata: The source primary key column name for the many to many mapping [field jobTitle] is being defaulted to: EMP_ID.
[EL Config]: metadata: The target primary key column name for the many to many mapping [field jobTitle] is being defaulted to: JOB_ID.
[EL Config]: metadata: The primary key column name for the mapping element [field degrees] is being defaulted to: EMP_ID.
[EL Config]: metadata: The primary key column name for the mapping element [field teamLeader] is being defaulted to: EMP_ID.
[EL Config]: metadata: The primary key column name for the mapping element [field emailAddresses] is being defaulted to: EMP_ID.
Creating new employee using persist.
[EL Info]: EclipseLink, version: Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd
[EL Fine]: connection: Detected database platform: org.eclipse.persistence.platform.database.oracle.Oracle11Platform
[EL Config]: connection: Connection(95553286)--connecting(DatabaseLogin(
platform=>Oracle11Platform
user name=> "develop"
datasource URL=> "jdbc:oracle:thin:@localhost:1521"
))
[EL Config]: connection: Connection(380556447)--Connected: jdbc:oracle:thin:@localhost:1521
User: DEVELOP
Database: Oracle Version: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
Driver: Oracle JDBC driver Version: 11.2.0.2.0
[EL Warning]: metadata: Reverting the lazy setting on the OneToOne or ManyToOne attribute [address] for the entity class [class model.Employee] since weaving was not enabled or did not occur.
[EL Warning]: metadata: Reverting the lazy setting on the OneToOne or ManyToOne attribute [manager] for the entity class [class model.Employee] since weaving was not enabled or did not occur.
[EL Warning]: metadata: Reverting the lazy setting on the OneToOne or ManyToOne attribute [jobTitle] for the entity class [class model.Employee] since weaving was not enabled or did not occur.
[EL Warning]: metadata: Reverting the lazy setting on the OneToOne or ManyToOne attribute [owner] for the entity class [class model.PhoneNumber] since weaving was not enabled or did not occur.
[EL Warning]: metadata: Reverting the lazy setting on the OneToOne or ManyToOne attribute [teamLeader] for the entity class [class model.Project] since weaving was not enabled or did not occur.
[EL Info]: connection: file:/C:/Users/Bext/Documents/NetBeansProjects/jpa_employee_annotations/build/classes/_employee login successful
[EL Fine]: sql: Connection(380556447)--ALTER TABLE PROJECT DROP CONSTRAINT FK_PROJECT_LEADER_ID
[EL Fine]: sql: Connection(380556447)--ALTER TABLE PHONE DROP CONSTRAINT FK_PHONE_EMP_ID
[EL Fine]: sql: Connection(380556447)--ALTER TABLE LPROJECT DROP CONSTRAINT FK_LPROJECT_PROJ_ID
[EL Fine]: sql: Connection(380556447)--ALTER TABLE EMPLOYEE DROP CONSTRAINT FK_EMPLOYEE_MANAGER_ID
[EL Fine]: sql: Connection(380556447)--ALTER TABLE EMPLOYEE DROP CONSTRAINT FK_EMPLOYEE_ADDR_ID
[EL Fine]: sql: Connection(380556447)--ALTER TABLE SALARY DROP CONSTRAINT FK_SALARY_EMP_ID
[EL Fine]: sql: Connection(380556447)--ALTER TABLE DEGREE DROP CONSTRAINT FK_DEGREE_EMP_ID
[EL Fine]: sql: Connection(380556447)--ALTER TABLE EMP_JOB DROP CONSTRAINT FK_EMP_JOB_EMP_ID
[EL Fine]: sql: Connection(380556447)--ALTER TABLE EMP_JOB DROP CONSTRAINT FK_EMP_JOB_TITLE_ID
[EL Fine]: sql: Connection(380556447)--ALTER TABLE EMAIL DROP CONSTRAINT FK_EMAIL_EMP_ID
[EL Fine]: sql: Connection(380556447)--ALTER TABLE RESPONS DROP CONSTRAINT FK_RESPONS_EMP_ID
[EL Fine]: sql: Connection(380556447)--ALTER TABLE PROJ_EMP DROP CONSTRAINT FK_PROJ_EMP_EMP_ID
[EL Fine]: sql: Connection(380556447)--ALTER TABLE PROJ_EMP DROP CONSTRAINT FK_PROJ_EMP_PROJ_ID
[EL Fine]: sql: Connection(380556447)--DROP TABLE PROJECT CASCADE CONSTRAINTS
[EL Fine]: sql: Connection(380556447)--DROP TABLE PHONE CASCADE CONSTRAINTS
[EL Fine]: sql: Connection(380556447)--DROP TABLE LPROJECT CASCADE CONSTRAINTS
[EL Fine]: sql: Connection(380556447)--DROP TABLE EMPLOYEE CASCADE CONSTRAINTS
[EL Fine]: sql: Connection(380556447)--DROP TABLE SALARY CASCADE CONSTRAINTS
[EL Fine]: sql: Connection(380556447)--DROP TABLE ADDRESS CASCADE CONSTRAINTS
[EL Fine]: sql: Connection(380556447)--DROP TABLE JOBTITLE CASCADE CONSTRAINTS
[EL Fine]: sql: Connection(380556447)--DROP TABLE DEGREE CASCADE CONSTRAINTS
[EL Fine]: sql: Connection(380556447)--DROP TABLE EMP_JOB CASCADE CONSTRAINTS
[EL Fine]: sql: Connection(380556447)--DROP TABLE EMAIL CASCADE CONSTRAINTS
[EL Fine]: sql: Connection(380556447)--DROP TABLE RESPONS CASCADE CONSTRAINTS
[EL Fine]: sql: Connection(380556447)--DROP TABLE PROJ_EMP CASCADE CONSTRAINTS
[EL Fine]: sql: Connection(380556447)--CREATE TABLE PROJECT (PROJ_ID NUMBER(10) NOT NULL, PROJ_TYPE VARCHAR2(31) NULL, DESCRIP VARCHAR2(255) NULL, PROJ_NAME VARCHAR2(255) NULL, VERSION NUMBER(19) NULL, LEADER_ID NUMBER(19) NULL, PRIMARY KEY (PROJ_ID))
[EL Fine]: sql: Connection(380556447)--CREATE TABLE PHONE (TYPE VARCHAR2(255) NOT NULL, AREA_CODE VARCHAR2(255) NULL, P_NUMBER VARCHAR2(255) NULL, EMP_ID NUMBER(19) NOT NULL, PRIMARY KEY (TYPE, EMP_ID))
[EL Fine]: sql: Connection(380556447)--CREATE TABLE LPROJECT (PROJ_ID NUMBER(10) NOT NULL, BUDGET NUMBER(19,4) NULL, MILESTONE TIMESTAMP NULL, PRIMARY KEY (PROJ_ID))
[EL Fine]: sql: Connection(380556447)--CREATE TABLE EMPLOYEE (EMP_ID NUMBER(19) NOT NULL, F_NAME VARCHAR2(255) NULL, GENDER VARCHAR2(255) NULL, L_NAME VARCHAR2(255) NULL, VERSION NUMBER(19) NULL, END_DATE DATE NULL, START_DATE DATE NULL, MANAGER_ID NUMBER(19) NULL, ADDR_ID NUMBER(19) NULL, PRIMARY KEY (EMP_ID))
[EL Fine]: sql: Connection(380556447)--CREATE TABLE SALARY (EMP_ID NUMBER(19) NOT NULL, SALARY NUMBER(19,4) NULL, PRIMARY KEY (EMP_ID))
[EL Fine]: sql: Connection(380556447)--CREATE TABLE ADDRESS (ADDRESS_ID NUMBER(19) NOT NULL, CITY VARCHAR2(255) NULL, COUNTRY VARCHAR2(255) NULL, P_CODE VARCHAR2(255) NULL, PROVINCE VARCHAR2(255) NULL, STREET VARCHAR2(255) NULL, PRIMARY KEY (ADDRESS_ID))
[EL Fine]: sql: Connection(380556447)--CREATE TABLE JOBTITLE (JOB_ID NUMBER(19) NOT NULL, TITLE VARCHAR2(255) NULL, PRIMARY KEY (JOB_ID))
[EL Fine]: sql: Connection(380556447)--CREATE TABLE DEGREE (DEGREE_ID NUMBER(19) NOT NULL, NAME VARCHAR2(255) NULL, EMP_ID NUMBER(19) NULL, PRIMARY KEY (DEGREE_ID))
[EL Fine]: sql: Connection(380556447)--CREATE TABLE EMP_JOB (EMP_ID NUMBER(19) NOT NULL, TITLE_ID NUMBER(19) NOT NULL, PRIMARY KEY (EMP_ID, TITLE_ID))
[EL Fine]: sql: Connection(380556447)--CREATE TABLE EMAIL (EMAIL_TYPE VARCHAR2(255) NULL, EMAIL_ADDRESS VARCHAR2(255) NULL, EMP_ID NUMBER(19) NULL)
[EL Fine]: sql: Connection(380556447)--CREATE TABLE RESPONS (EMP_ID NUMBER(19) NULL, RESPONSIBILITY VARCHAR2(255) NULL, PRIORITY NUMBER(10) NULL)
[EL Fine]: sql: Connection(380556447)--CREATE TABLE PROJ_EMP (EMP_ID NUMBER(19) NOT NULL, PROJ_ID NUMBER(10) NOT NULL, PRIMARY KEY (EMP_ID, PROJ_ID))
[EL Fine]: sql: Connection(380556447)--ALTER TABLE PROJECT ADD CONSTRAINT FK_PROJECT_LEADER_ID FOREIGN KEY (LEADER_ID) REFERENCES EMPLOYEE (EMP_ID)
[EL Fine]: sql: Connection(380556447)--ALTER TABLE PHONE ADD CONSTRAINT FK_PHONE_EMP_ID FOREIGN KEY (EMP_ID) REFERENCES EMPLOYEE (EMP_ID)
[EL Fine]: sql: Connection(380556447)--ALTER TABLE LPROJECT ADD CONSTRAINT FK_LPROJECT_PROJ_ID FOREIGN KEY (PROJ_ID) REFERENCES PROJECT (PROJ_ID)
[EL Fine]: sql: Connection(380556447)--ALTER TABLE EMPLOYEE ADD CONSTRAINT FK_EMPLOYEE_MANAGER_ID FOREIGN KEY (MANAGER_ID) REFERENCES EMPLOYEE (EMP_ID)
[EL Fine]: sql: Connection(380556447)--ALTER TABLE EMPLOYEE ADD CONSTRAINT FK_EMPLOYEE_ADDR_ID FOREIGN KEY (ADDR_ID) REFERENCES ADDRESS (ADDRESS_ID)
[EL Fine]: sql: Connection(380556447)--ALTER TABLE SALARY ADD CONSTRAINT FK_SALARY_EMP_ID FOREIGN KEY (EMP_ID) REFERENCES EMPLOYEE (EMP_ID)
[EL Fine]: sql: Connection(380556447)--ALTER TABLE DEGREE ADD CONSTRAINT FK_DEGREE_EMP_ID FOREIGN KEY (EMP_ID) REFERENCES EMPLOYEE (EMP_ID)
[EL Fine]: sql: Connection(380556447)--ALTER TABLE EMP_JOB ADD CONSTRAINT FK_EMP_JOB_EMP_ID FOREIGN KEY (EMP_ID) REFERENCES EMPLOYEE (EMP_ID)
[EL Fine]: sql: Connection(380556447)--ALTER TABLE EMP_JOB ADD CONSTRAINT FK_EMP_JOB_TITLE_ID FOREIGN KEY (TITLE_ID) REFERENCES JOBTITLE (JOB_ID)
[EL Fine]: sql: Connection(380556447)--ALTER TABLE EMAIL ADD CONSTRAINT FK_EMAIL_EMP_ID FOREIGN KEY (EMP_ID) REFERENCES EMPLOYEE (EMP_ID)
[EL Fine]: sql: Connection(380556447)--ALTER TABLE RESPONS ADD CONSTRAINT FK_RESPONS_EMP_ID FOREIGN KEY (EMP_ID) REFERENCES EMPLOYEE (EMP_ID)
[EL Fine]: sql: Connection(380556447)--ALTER TABLE PROJ_EMP ADD CONSTRAINT FK_PROJ_EMP_EMP_ID FOREIGN KEY (EMP_ID) REFERENCES EMPLOYEE (EMP_ID)
[EL Fine]: sql: Connection(380556447)--ALTER TABLE PROJ_EMP ADD CONSTRAINT FK_PROJ_EMP_PROJ_ID FOREIGN KEY (PROJ_ID) REFERENCES PROJECT (PROJ_ID)
[EL Fine]: sql: Connection(380556447)--DROP SEQUENCE SEQ_GEN_SEQUENCE
[EL Fine]: sql: Connection(380556447)--SELECT SEQ_GEN_SEQUENCE.NEXTVAL FROM DUAL
[EL Fine]: sql: SELECT 1 FROM DUAL
[EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist
Error Code: 2289
Call: SELECT SEQ_GEN_SEQUENCE.NEXTVAL FROM DUAL
Query: ValueReadQuery(sql="SELECT SEQ_GEN_SEQUENCE.NEXTVAL FROM DUAL")
[EL Fine]: sql: Connection(380556447)--CREATE SEQUENCE SEQ_GEN_SEQUENCE INCREMENT BY 50 START WITH 50
[EL Fine]: sql: Connection(380556447)--SELECT SEQ_GEN_SEQUENCE.NEXTVAL FROM DUAL
[EL Fine]: sql: Connection(380556447)--INSERT INTO ADDRESS (ADDRESS_ID, CITY, COUNTRY, P_CODE, PROVINCE, STREET) VALUES (?, ?, ?, ?, ?, ?)
bind => [2, null, null, null, null, null]
[EL Fine]: sql: Connection(380556447)--INSERT INTO EMPLOYEE (EMP_ID, F_NAME, GENDER, L_NAME, VERSION, END_DATE, START_DATE, MANAGER_ID, ADDR_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [1, Sample, Male, Employee, 1, null, null, null, 2]
[EL Fine]: sql: Connection(380556447)--INSERT INTO PHONE (TYPE, AREA_CODE, P_NUMBER, EMP_ID) VALUES (?, ?, ?, ?)
bind => [Mobile, 613, 555-1212, 1]
[EL Fine]: sql: Connection(380556447)--INSERT INTO SALARY (SALARY, EMP_ID) VALUES (?, ?)
bind => [123456.0, 1]
Creating new employee using merge.
[EL Fine]: sql: Connection(380556447)--SELECT TYPE, AREA_CODE, P_NUMBER, EMP_ID FROM PHONE WHERE ((TYPE = ?) AND (EMP_ID = ?))
bind => [Mobile, 0]
[EL Fine]: sql: Connection(380556447)--INSERT INTO ADDRESS (ADDRESS_ID, CITY, COUNTRY, P_CODE, PROVINCE, STREET) VALUES (?, ?, ?, ?, ?, ?)
bind => [4, null, null, null, null, null]
[EL Fine]: sql: Connection(380556447)--INSERT INTO EMPLOYEE (EMP_ID, F_NAME, GENDER, L_NAME, VERSION, END_DATE, START_DATE, MANAGER_ID, ADDR_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [3, Sample, Male, Employee, 1, null, null, null, 4]
[EL Fine]: sql: Connection(380556447)--INSERT INTO PHONE (TYPE, AREA_CODE, P_NUMBER, EMP_ID) VALUES (?, ?, ?, ?)
bind => [Mobile, 613, 555-1212, 3]
[EL Fine]: sql: Connection(380556447)--INSERT INTO SALARY (SALARY, EMP_ID) VALUES (?, ?)
bind => [123456.0, 3]
Using pessimistic locking on employee.
[EL Fine]: sql: Connection(380556447)--SELECT t0.EMP_ID FROM EMPLOYEE t0, SALARY t1 WHERE (t1.EMP_ID = t0.EMP_ID)
[EL Fine]: sql: Connection(380556447)--SELECT t0.EMP_ID, t1.EMP_ID, t0.F_NAME, t0.GENDER, t0.L_NAME, t1.SALARY, t0.VERSION, t0.END_DATE, t0.START_DATE, t0.MANAGER_ID, t0.ADDR_ID FROM EMPLOYEE t0, SALARY t1 WHERE ((t0.EMP_ID = ?) AND (t1.EMP_ID = t0.EMP_ID)) FOR UPDATE
bind => [1]
[EL Fine]: sql: Connection(380556447)--SELECT t1.JOB_ID, t1.TITLE FROM EMP_JOB t0, JOBTITLE t1 WHERE ((t0.EMP_ID = ?) AND (t1.JOB_ID = t0.TITLE_ID))
bind => [1]
[EL Fine]: sql: Connection(380556447)--SELECT EMAIL_ADDRESS, EMAIL_TYPE, EMP_ID FROM EMAIL WHERE (EMP_ID = ?)
bind => [1]
[EL Fine]: sql: Connection(380556447)--SELECT t0.RESPONSIBILITY, t0.PRIORITY FROM RESPONS t0 WHERE (t0.EMP_ID = ?)
bind => [1]
[EL Fine]: sql: Connection(380556447)--SELECT DISTINCT t1.PROJ_TYPE FROM PROJ_EMP t0, PROJECT t1 WHERE ((t0.EMP_ID = ?) AND (t1.PROJ_ID = t0.PROJ_ID))
bind => [1]
[EL Fine]: sql: Connection(380556447)--SELECT t0.EMP_ID, t1.EMP_ID, t0.F_NAME, t0.GENDER, t0.L_NAME, t1.SALARY, t0.VERSION, t0.END_DATE, t0.START_DATE, t0.MANAGER_ID, t0.ADDR_ID FROM EMPLOYEE t0, SALARY t1 WHERE ((t0.MANAGER_ID = ?) AND (t1.EMP_ID = t0.EMP_ID))
bind => [1]
[EL Fine]: sql: Connection(380556447)--SELECT TYPE, AREA_CODE, P_NUMBER, EMP_ID FROM PHONE WHERE (EMP_ID = ?)
bind => [1]
[EL Fine]: sql: Connection(380556447)--SELECT DEGREE_ID, NAME FROM DEGREE WHERE (EMP_ID = ?)
bind => [1]
[EL Fine]: sql: Connection(380556447)--UPDATE EMPLOYEE SET VERSION = ? WHERE ((EMP_ID = ?) AND (VERSION = ?))
bind => [2, 1, 1]
[EL Fine]: sql: Connection(380556447)--UPDATE SALARY SET SALARY = ? WHERE (EMP_ID = ?)
bind => [123455.0, 1]
Querying employee and its address' city and updating the employee's salary.
[EL Fine]: sql: Connection(380556447)--SELECT t0.EMP_ID, t1.EMP_ID, t0.F_NAME, t0.GENDER, t0.L_NAME, t1.SALARY, t0.VERSION, t0.END_DATE, t0.START_DATE, t0.MANAGER_ID, t0.ADDR_ID, t2.CITY FROM EMPLOYEE t0, ADDRESS t2, SALARY t1 WHERE ((t1.EMP_ID = t0.EMP_ID) AND (t2.ADDRESS_ID = t0.ADDR_ID))
[EL Fine]: sql: Connection(380556447)--UPDATE EMPLOYEE SET VERSION = ? WHERE ((EMP_ID = ?) AND (VERSION = ?))
bind => [3, 1, 2]
[EL Fine]: sql: Connection(380556447)--UPDATE SALARY SET SALARY = ? WHERE (EMP_ID = ?)
bind => [123456.0, 1]
[EL Config]: connection: Connection(380556447)--disconnect
[EL Info]: connection: file:/C:/Users/Bext/Documents/NetBeansProjects/jpa_employee_annotations/build/classes/_employee logout successful
[EL Config]: connection: Connection(95553286)--disconnect
BUILD SUCCESSFUL (total time: 9 seconds)
Cabe mensionar que el archivo pesistence.xml de configuración del persistence unit tiene una propiedad que borra y crea las tablas a partir del código java que describe las entidades
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
así que si se vuelve a correr las borrará y creará de nuevo.
las tablas generadas vistas desde ide Netbeans :
Suscribirse a:
Entradas (Atom)