Merge pull request #387 from giuseppebueti/master
Removed Oracle setup and java code
This commit is contained in:
commit
9e3d7a3b22
|
@ -9,8 +9,8 @@
|
|||
|
||||
<properties>
|
||||
<jee.version>7.0</jee.version>
|
||||
<oracle.version>11.2.0.4</oracle.version>
|
||||
<hibernate.version>5.1.0.Final</hibernate.version>
|
||||
<mysql.version>5.1.38</mysql.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
@ -33,29 +33,6 @@
|
|||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>install-oracle-jdbc</id>
|
||||
<goals>
|
||||
<goal>install-file</goal>
|
||||
</goals>
|
||||
<phase>clean</phase>
|
||||
<configuration>
|
||||
<groupId>com.oracle</groupId>
|
||||
<artifactId>ojdbc6</artifactId>
|
||||
<version>${oracle.version}</version>
|
||||
<packaging>jar</packaging>
|
||||
<generatePom>true</generatePom>
|
||||
<createChecksum>true</createChecksum>
|
||||
<file>${project.basedir}/src/lib/ojdbc6.jar</file>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
@ -76,20 +53,6 @@
|
|||
<version>${hibernate.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Oracle JDBC -->
|
||||
<dependency>
|
||||
<groupId>com.oracle</groupId>
|
||||
<artifactId>ojdbc6</artifactId>
|
||||
<version>${oracle.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Postgres JDBC -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>9.4.1208</version>
|
||||
</dependency>
|
||||
|
||||
<!-- MySql JDBC -->
|
||||
|
||||
<dependency>
|
||||
|
|
Binary file not shown.
|
@ -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;
|
||||
|
|
|
@ -9,22 +9,12 @@
|
|||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.baeldung.jpa.model.Car</class>
|
||||
<properties>
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
|
||||
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@//127.0.0.1:1521/xe" />
|
||||
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver" />
|
||||
<property name="hibernate.connection.username" value="JPA" />
|
||||
<property name="hibernate.connection.password" value="JPA" />
|
||||
<property name="hibernate.show_sql" value="true" />
|
||||
</properties>
|
||||
|
||||
<!-- MySQL properties configuration -->
|
||||
<!--properties>
|
||||
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/jpa" />
|
||||
<property name="javax.persistence.jdbc.user" value="jpa" />
|
||||
<property name="javax.persistence.jdbc.password" value="bagnara.82" />
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/baeldung" />
|
||||
<property name="javax.persistence.jdbc.user" value="baeldung" />
|
||||
<property name="javax.persistence.jdbc.password" value="YourPassword" />
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
|
||||
<property name="hibernate.show_sql" value="true" />
|
||||
</properties-->
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
|
@ -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;
|
|
@ -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;
|
||||
|
|
@ -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;
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
@ -9,23 +9,13 @@
|
|||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>com.baeldung.jpa.model.Car</class>
|
||||
<properties>
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
|
||||
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@//127.0.0.1:1521/xe" />
|
||||
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver" />
|
||||
<property name="hibernate.connection.username" value="JPA" />
|
||||
<property name="hibernate.connection.password" value="JPA" />
|
||||
<property name="hibernate.show_sql" value="true" />
|
||||
</properties>
|
||||
|
||||
<!-- MySQL properties configuration -->
|
||||
<!--properties>
|
||||
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/jpa" />
|
||||
<property name="javax.persistence.jdbc.user" value="jpa" />
|
||||
<property name="javax.persistence.jdbc.password" value="bagnara.82" />
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/baeldung" />
|
||||
<property name="javax.persistence.jdbc.user" value="baeldung" />
|
||||
<property name="javax.persistence.jdbc.password" value="YourPassword" />
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
|
||||
<property name="hibernate.show_sql" value="true" />
|
||||
</properties-->
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
|
||||
|
|
Loading…
Reference in New Issue