diff --git a/jpa-storedprocedure/pom.xml b/jpa-storedprocedure/pom.xml index bbe00d6897..b2ebaa32e2 100644 --- a/jpa-storedprocedure/pom.xml +++ b/jpa-storedprocedure/pom.xml @@ -9,8 +9,8 @@ 7.0 - 11.2.0.4 5.1.0.Final + 5.1.38 @@ -33,29 +33,6 @@ - - org.apache.maven.plugins - maven-install-plugin - 2.3.1 - - - install-oracle-jdbc - - install-file - - clean - - com.oracle - ojdbc6 - ${oracle.version} - jar - true - true - ${project.basedir}/src/lib/ojdbc6.jar - - - - @@ -76,20 +53,6 @@ ${hibernate.version} - - - com.oracle - ojdbc6 - ${oracle.version} - - - - - org.postgresql - postgresql - 9.4.1208 - - diff --git a/jpa-storedprocedure/src/lib/ojdbc6.jar b/jpa-storedprocedure/src/lib/ojdbc6.jar deleted file mode 100644 index 767eba7f8f..0000000000 Binary files a/jpa-storedprocedure/src/lib/ojdbc6.jar and /dev/null differ diff --git a/jpa-storedprocedure/src/main/java/com/baeldung/jpa/model/Car.java b/jpa-storedprocedure/src/main/java/com/baeldung/jpa/model/Car.java index ea6c38dd8e..bd7c775614 100644 --- a/jpa-storedprocedure/src/main/java/com/baeldung/jpa/model/Car.java +++ b/jpa-storedprocedure/src/main/java/com/baeldung/jpa/model/Car.java @@ -9,10 +9,8 @@ import javax.persistence.*; @Entity @Table(name = "CAR") @NamedStoredProcedureQueries({ - @NamedStoredProcedureQuery(name = "findByModelProcedure", procedureName = "FIND_CAR_BY_MODEL", resultClasses = { Car.class }, parameters = { @StoredProcedureParameter(name = "data", type = Car.class, mode = ParameterMode.REF_CURSOR), - @StoredProcedureParameter(name = "p_model", type = String.class, mode = ParameterMode.IN) }), - @NamedStoredProcedureQuery(name = "findByYearProcedure", procedureName = "FIND_CAR_BY_YEAR", resultClasses = { Car.class }, parameters = { @StoredProcedureParameter(name = "data", type = Car.class, mode = ParameterMode.REF_CURSOR), - @StoredProcedureParameter(name = "p_year", type = Integer.class, mode = ParameterMode.IN) }) }) + @NamedStoredProcedureQuery(name = "findByYearProcedure", procedureName = "FIND_CAR_BY_YEAR", resultClasses = { Car.class }, + parameters = { @StoredProcedureParameter(name = "p_year", type = Integer.class, mode = ParameterMode.IN) }) }) public class Car { private long id; @@ -28,9 +26,7 @@ public class Car { } @Id - @SequenceGenerator(name = "CarIdSequence", sequenceName = "SEQ_CAR_ID", allocationSize = 1) - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CarIdSequence") - // @GeneratedValue(strategy = GenerationType.IDENTITY) -- for MySQL + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID", unique = true, nullable = false, scale = 0) public long getId() { return id; diff --git a/jpa-storedprocedure/src/main/resources/META-INF/persistence.xml b/jpa-storedprocedure/src/main/resources/META-INF/persistence.xml index 3cb81fc9c1..4c443cb7cf 100644 --- a/jpa-storedprocedure/src/main/resources/META-INF/persistence.xml +++ b/jpa-storedprocedure/src/main/resources/META-INF/persistence.xml @@ -9,22 +9,12 @@ org.hibernate.jpa.HibernatePersistenceProvider com.baeldung.jpa.model.Car - - - - - - - - - - + \ No newline at end of file diff --git a/jpa-storedprocedure/src/main/resources/config/database/FindCarByYearProcedureOracle.sql b/jpa-storedprocedure/src/main/resources/config/database/FindCarByYearProcedureOracle.sql deleted file mode 100644 index f9230aad42..0000000000 --- a/jpa-storedprocedure/src/main/resources/config/database/FindCarByYearProcedureOracle.sql +++ /dev/null @@ -1,7 +0,0 @@ -create or replace PROCEDURE FIND_CAR_BY_YEAR ( p_year IN NUMBER, data OUT SYS_REFCURSOR ) AS - BEGIN - OPEN data FOR - SELECT ID, MODEL, YEAR - FROM CAR - WHERE YEAR = p_year; - END FIND_CAR_BY_YEAR; \ No newline at end of file diff --git a/jpa-storedprocedure/src/main/resources/config/database/create_database.sql b/jpa-storedprocedure/src/main/resources/config/database/create_database.sql deleted file mode 100644 index d84007b74d..0000000000 --- a/jpa-storedprocedure/src/main/resources/config/database/create_database.sql +++ /dev/null @@ -1,34 +0,0 @@ -CREATE TABLESPACE JPA DATAFILE 'C:\oraclexe\app\oracle\oradata\XE\JPA.DBF' SIZE 100M AUTOEXTEND ON MAXSIZE 2048M; - ---DROP USER JPA CASCADE; -CREATE USER JPA IDENTIFIED BY JPA DEFAULT TABLESPACE JPA; -ALTER USER JPA QUOTA UNLIMITED ON "JPA" ACCOUNT UNLOCK; - -GRANT CREATE SESSION TO "JPA"; -GRANT ALTER SESSION TO "JPA"; -GRANT CREATE TABLE TO "JPA"; -GRANT CREATE TRIGGER TO "JPA"; -GRANT CREATE VIEW TO "JPA"; -GRANT CREATE DIMENSION TO "JPA"; -GRANT CREATE CLUSTER TO "JPA"; -GRANT CREATE INDEXTYPE TO "JPA"; -GRANT CREATE ROLE TO "JPA"; -GRANT CREATE SEQUENCE TO "JPA"; -GRANT CREATE TYPE TO "JPA"; -GRANT CREATE MATERIALIZED VIEW TO "JPA"; -GRANT CREATE PROCEDURE TO "JPA"; -GRANT CREATE SYNONYM TO "JPA"; - -CREATE SEQUENCE SEQ_CAR_ID INCREMENT BY 1 START WITH 1 MAXVALUE 999999999999999 MINVALUE 1; - -CREATE TABLE CAR -( - ID NUMBER NOT NULL, - MODEL VARCHAR2(50) NOT NULL, - YEAR NUMBER(4) NOT NULL -); - -ALTER TABLE CAR ADD CONSTRAINT CAR_PK PRIMARY KEY ( ID ); - -commit; - diff --git a/jpa-storedprocedure/src/main/resources/config/database/insert_cars.sql b/jpa-storedprocedure/src/main/resources/config/database/insert_cars.sql index 4879ffc79e..89f69ac1ee 100644 --- a/jpa-storedprocedure/src/main/resources/config/database/insert_cars.sql +++ b/jpa-storedprocedure/src/main/resources/config/database/insert_cars.sql @@ -1,5 +1,5 @@ INSERT INTO CAR (ID, MODEL, YEAR) VALUES ('123456', 'Camaro', '2012'); -INSERT INTO "JPA"."CAR" (ID, MODEL, YEAR) VALUES ('12112', 'Fiat Panda', '2000'); -INSERT INTO "JPA"."CAR" (ID, MODEL, YEAR) VALUES ('111000', 'Fiat Punto', '2007'); -INSERT INTO "JPA"."CAR" (ID, MODEL, YEAR) VALUES ('3382', 'Citroen C3', '2009'); +INSERT INTO CAR (ID, MODEL, YEAR) VALUES ('12112', 'Fiat Panda', '2000'); +INSERT INTO CAR (ID, MODEL, YEAR) VALUES ('111000', 'Fiat Punto', '2007'); +INSERT INTO CAR (ID, MODEL, YEAR) VALUES ('3382', 'Citroen C3', '2009'); commit; \ No newline at end of file diff --git a/jpa-storedprocedure/src/test/java/com/baeldung/jpa/storedprocedure/StoredProcedureTest.java b/jpa-storedprocedure/src/test/java/com/baeldung/jpa/storedprocedure/StoredProcedureTest.java index 9d66c9f15c..c1fabcc24c 100644 --- a/jpa-storedprocedure/src/test/java/com/baeldung/jpa/storedprocedure/StoredProcedureTest.java +++ b/jpa-storedprocedure/src/test/java/com/baeldung/jpa/storedprocedure/StoredProcedureTest.java @@ -28,7 +28,7 @@ public class StoredProcedureTest { EntityTransaction transaction = entityManager.getTransaction(); try { transaction.begin(); - Car car = new Car("Fiat Punto", 2015); + Car car = new Car("Fiat Marea", 2015); entityManager.persist(car); transaction.commit(); } catch (Exception e) { @@ -40,30 +40,14 @@ public class StoredProcedureTest { } @Test - public void findCarsByYear() { + public void findCarsByYearNamedProcedure() { final StoredProcedureQuery findByYearProcedure = entityManager.createNamedStoredProcedureQuery("findByYearProcedure"); StoredProcedureQuery storedProcedure = findByYearProcedure.setParameter("p_year", 2015); storedProcedure.getResultList().forEach(c -> Assert.assertEquals(new Integer(2015), ((Car) c).getYear())); } @Test - public void findCarsByModel() { - final StoredProcedureQuery findByModelProcedure = entityManager.createNamedStoredProcedureQuery("findByModelProcedure"); - StoredProcedureQuery storedProcedure = findByModelProcedure.setParameter("p_model", "Camaro"); - storedProcedure.getResultList().forEach(c -> Assert.assertEquals("Camaro", ((Car) c).getModel())); - } - - @Test - public void findCarsByYearNoNamedStored() { - StoredProcedureQuery findByYearProcedure = entityManager.createStoredProcedureQuery("FIND_CAR_BY_YEAR", Car.class).registerStoredProcedureParameter("data", Void.class, ParameterMode.REF_CURSOR) - .registerStoredProcedureParameter("p_year", Integer.class, ParameterMode.IN).setParameter("p_year", 2015); - - findByYearProcedure.getResultList().forEach(c -> Assert.assertEquals(new Integer(2015), ((Car) c).getYear())); - } - - @Test - @Ignore - public void findCarsByYearMySql() { + public void findCarsByYearNoNamed() { StoredProcedureQuery storedProcedure = entityManager.createStoredProcedureQuery("FIND_CAR_BY_YEAR", Car.class).registerStoredProcedureParameter(1, Integer.class, ParameterMode.IN).setParameter(1, 2015); storedProcedure.getResultList().forEach(c -> Assert.assertEquals(new Integer(2015), ((Car) c).getYear())); } diff --git a/jpa-storedprocedure/src/test/resources/persistence.xml b/jpa-storedprocedure/src/test/resources/persistence.xml index d118a264d3..d94221b54f 100644 --- a/jpa-storedprocedure/src/test/resources/persistence.xml +++ b/jpa-storedprocedure/src/test/resources/persistence.xml @@ -9,23 +9,13 @@ org.hibernate.jpa.HibernatePersistenceProvider com.baeldung.jpa.model.Car - - - - - - - - - - +