JAVA-20164 Upgrade java hibernate specific modules to JDK 11 (#13900)
* JAVA-20164 Upgrade java hibernate specific modules to JDK 11 * JAVA-20164 Migrating java-jpa-2 * JAVA-20164 Migrating jnosql-artemis * JAVA-20164 Migrating querydsl * JAVA-20164 Migrating r2dbc * JAVA-20164 Migrating redis * JAVA-20164 Fixing test JPATextUnitTest#givenExam_whenSaveExam_thenReturnExpectedExam * JAVA-20164 Fixing givenIdentityStrategy_whenCommitTransction_thenReturnPrimaryKey * JAVA-20164 Changes after review * JAVA-20164 Migrating java-cassandra to jdk8 * JAVA-20164 Fix legacy mode error * Update pom.xml --------- Co-authored-by: timis1 <noreplay@yahoo.com> Co-authored-by: Dhawal Kapil <dhawalkapil@gmail.com>
This commit is contained in:
parent
09e421c3cd
commit
e624a6c893
|
@ -14,32 +14,44 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
<artifactId>hibernate-core</artifactId>
|
<artifactId>hibernate-core</artifactId>
|
||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>jakarta.xml.bind</groupId>
|
||||||
|
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
<artifactId>hibernate-jpamodelgen</artifactId>
|
<artifactId>hibernate-jpamodelgen</artifactId>
|
||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>jakarta.xml.bind</groupId>
|
||||||
|
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<version>${h2.version}</version>
|
<version>${h2.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--Compile time JPA API -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.persistence</groupId>
|
|
||||||
<artifactId>javax.persistence-api</artifactId>
|
|
||||||
<version>${javax.persistence-api.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!--Runtime JPA implementation -->
|
<!--Runtime JPA implementation -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.persistence</groupId>
|
<groupId>org.eclipse.persistence</groupId>
|
||||||
<artifactId>eclipselink</artifactId>
|
<artifactId>eclipselink</artifactId>
|
||||||
<version>${eclipselink.version}</version>
|
<version>${eclipselink.version}</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>jakarta.xml.bind</groupId>
|
||||||
|
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
|
@ -51,13 +63,25 @@
|
||||||
<groupId>com.querydsl</groupId>
|
<groupId>com.querydsl</groupId>
|
||||||
<artifactId>querydsl-apt</artifactId>
|
<artifactId>querydsl-apt</artifactId>
|
||||||
<version>${querydsl.version}</version>
|
<version>${querydsl.version}</version>
|
||||||
|
<classifier>jakarta</classifier>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.querydsl</groupId>
|
<groupId>com.querydsl</groupId>
|
||||||
<artifactId>querydsl-jpa</artifactId>
|
<artifactId>querydsl-jpa</artifactId>
|
||||||
|
<classifier>jakarta</classifier>
|
||||||
<version>${querydsl.version}</version>
|
<version>${querydsl.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.xml.bind</groupId>
|
||||||
|
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||||
|
<version>${jakarta.xml.bind-api.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.annotation</groupId>
|
||||||
|
<artifactId>javax.annotation-api</artifactId>
|
||||||
|
<version>${javax.annotation.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -130,14 +154,15 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<hibernate.version>5.4.14.Final</hibernate.version>
|
<eclipselink.version>4.0.1</eclipselink.version>
|
||||||
<eclipselink.version>2.7.4</eclipselink.version>
|
|
||||||
<javax.persistence-api.version>2.2</javax.persistence-api.version>
|
<javax.persistence-api.version>2.2</javax.persistence-api.version>
|
||||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||||
<maven-processor-plugin.version>3.3.3</maven-processor-plugin.version>
|
<maven-processor-plugin.version>3.3.3</maven-processor-plugin.version>
|
||||||
<build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
|
<build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
|
||||||
<querydsl.version>4.3.1</querydsl.version>
|
<querydsl.version>5.0.0</querydsl.version>
|
||||||
<h2.version>2.1.214</h2.version>
|
<h2.version>1.4.200</h2.version>
|
||||||
|
<jakarta.xml.bind-api.version>4.0.0</jakarta.xml.bind-api.version>
|
||||||
|
<javax.annotation.version>1.3.2</javax.annotation.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -2,13 +2,13 @@ package com.baeldung.jpa.criteria;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import jakarta.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Predicate;
|
import jakarta.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import jakarta.persistence.criteria.Root;
|
||||||
|
|
||||||
public class CustomItemRepositoryImpl implements CustomItemRepository {
|
public class CustomItemRepositoryImpl implements CustomItemRepository {
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.baeldung.jpa.criteria;
|
package com.baeldung.jpa.criteria;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Table(name = "item")
|
@Table(name = "item")
|
||||||
@Entity
|
@Entity
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package com.baeldung.jpa.defaultvalues;
|
package com.baeldung.jpa.defaultvalues;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
@Entity(name = "users")
|
@Entity(name = "users")
|
||||||
public class User {
|
public class User {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.baeldung.jpa.defaultvalues;
|
package com.baeldung.jpa.defaultvalues;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
|
|
||||||
public class UserRepository {
|
public class UserRepository {
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.baeldung.jpa.entity;
|
package com.baeldung.jpa.entity;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity(name = "MyArticle")
|
@Entity(name = "MyArticle")
|
||||||
@Table(name = Article.TABLE_NAME)
|
@Table(name = Article.TABLE_NAME)
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.baeldung.jpa.generateidvalue;
|
package com.baeldung.jpa.generateidvalue;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "app_admin")
|
@Table(name = "app_admin")
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package com.baeldung.jpa.generateidvalue;
|
package com.baeldung.jpa.generateidvalue;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.SequenceGenerator;
|
import jakarta.persistence.SequenceGenerator;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "article")
|
@Table(name = "article")
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package com.baeldung.jpa.generateidvalue;
|
package com.baeldung.jpa.generateidvalue;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Table(name = "id_gen")
|
@Table(name = "id_gen")
|
||||||
@Entity
|
@Entity
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package com.baeldung.jpa.generateidvalue;
|
package com.baeldung.jpa.generateidvalue;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import javax.persistence.TableGenerator;
|
import jakarta.persistence.TableGenerator;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "task")
|
@Table(name = "task")
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package com.baeldung.jpa.generateidvalue;
|
package com.baeldung.jpa.generateidvalue;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "app_user")
|
@Table(name = "app_user")
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package com.baeldung.jpa.multipletables.multipleentities;
|
package com.baeldung.jpa.multipletables.multipleentities;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.OneToOne;
|
import jakarta.persistence.OneToOne;
|
||||||
import javax.persistence.PrimaryKeyJoinColumn;
|
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
import com.baeldung.jpa.multipletables.secondarytable.MealAsSingleEntity;
|
import com.baeldung.jpa.multipletables.secondarytable.MealAsSingleEntity;
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,13 @@ package com.baeldung.jpa.multipletables.multipleentities;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.OneToOne;
|
import jakarta.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "meal")
|
@Table(name = "meal")
|
||||||
|
|
|
@ -2,14 +2,14 @@ package com.baeldung.jpa.multipletables.secondarytable;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.PrimaryKeyJoinColumn;
|
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||||
import javax.persistence.SecondaryTable;
|
import jakarta.persistence.SecondaryTable;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "meal")
|
@Table(name = "meal")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.baeldung.jpa.multipletables.secondarytable.embeddable;
|
package com.baeldung.jpa.multipletables.secondarytable.embeddable;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Embeddable;
|
import jakarta.persistence.Embeddable;
|
||||||
|
|
||||||
@Embeddable
|
@Embeddable
|
||||||
public class AllergensAsEmbeddable {
|
public class AllergensAsEmbeddable {
|
||||||
|
|
|
@ -2,15 +2,15 @@ package com.baeldung.jpa.multipletables.secondarytable.embeddable;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Embedded;
|
import jakarta.persistence.Embedded;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.PrimaryKeyJoinColumn;
|
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||||
import javax.persistence.SecondaryTable;
|
import jakarta.persistence.SecondaryTable;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "meal")
|
@Table(name = "meal")
|
||||||
|
|
|
@ -2,10 +2,8 @@ package com.baeldung.jpa.projections;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Product {
|
public class Product {
|
||||||
|
|
|
@ -2,14 +2,14 @@ package com.baeldung.jpa.projections;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
import javax.persistence.Query;
|
import jakarta.persistence.Query;
|
||||||
import javax.persistence.Tuple;
|
import jakarta.persistence.Tuple;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import jakarta.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Root;
|
import jakarta.persistence.criteria.Root;
|
||||||
|
|
||||||
public class ProductRepository {
|
public class ProductRepository {
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package com.baeldung.jpa.queryparams;
|
package com.baeldung.jpa.queryparams;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "employees")
|
@Table(name = "employees")
|
||||||
|
|
|
@ -3,14 +3,14 @@ package com.baeldung.jpa.querytypes;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
import javax.persistence.Query;
|
import jakarta.persistence.Query;
|
||||||
import javax.persistence.TypedQuery;
|
import jakarta.persistence.TypedQuery;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import jakarta.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Root;
|
import jakarta.persistence.criteria.Root;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JPA Query Types examples. All using the UserEntity class.
|
* JPA Query Types examples. All using the UserEntity class.
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.baeldung.jpa.querytypes;
|
package com.baeldung.jpa.querytypes;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.NamedQuery;
|
import jakarta.persistence.NamedQuery;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User entity class. Used as an asset for JPA Query Types examples.
|
* User entity class. Used as an asset for JPA Query Types examples.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.jpa.text;
|
package com.baeldung.jpa.text;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Exam {
|
public class Exam {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.baeldung.jpa.text;
|
package com.baeldung.jpa.text;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
|
|
||||||
public class ExamRepository {
|
public class ExamRepository {
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package com.baeldung.jpa.unrelated.entities;
|
package com.baeldung.jpa.unrelated.entities;
|
||||||
|
|
||||||
import org.hibernate.annotations.Fetch;
|
|
||||||
import org.hibernate.annotations.FetchMode;
|
|
||||||
import org.hibernate.annotations.NotFound;
|
import org.hibernate.annotations.NotFound;
|
||||||
import org.hibernate.annotations.NotFoundAction;
|
import org.hibernate.annotations.NotFoundAction;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@ -27,18 +25,17 @@ public class Cocktail {
|
||||||
@JoinColumn(name = "cocktail_name",
|
@JoinColumn(name = "cocktail_name",
|
||||||
referencedColumnName = "cocktail",
|
referencedColumnName = "cocktail",
|
||||||
insertable = false, updatable = false,
|
insertable = false, updatable = false,
|
||||||
foreignKey = @javax.persistence
|
foreignKey = @jakarta.persistence
|
||||||
.ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
|
.ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
|
||||||
private Recipe recipe;
|
private Recipe recipe;
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.LAZY)
|
@OneToMany(fetch = FetchType.LAZY)
|
||||||
@NotFound(action = NotFoundAction.IGNORE)
|
|
||||||
@JoinColumn(
|
@JoinColumn(
|
||||||
name = "cocktail",
|
name = "cocktail",
|
||||||
referencedColumnName = "cocktail_name",
|
referencedColumnName = "cocktail_name",
|
||||||
insertable = false,
|
insertable = false,
|
||||||
updatable = false,
|
updatable = false,
|
||||||
foreignKey = @javax.persistence
|
foreignKey = @jakarta.persistence
|
||||||
.ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
|
.ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
|
||||||
private List<MultipleRecipe> recipeList;
|
private List<MultipleRecipe> recipeList;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.baeldung.jpa.unrelated.entities;
|
package com.baeldung.jpa.unrelated.entities;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.baeldung.jpa.unrelated.entities;
|
package com.baeldung.jpa.unrelated.entities;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
|
version="3.0"
|
||||||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
|
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd">
|
||||||
version="2.2">
|
|
||||||
|
|
||||||
<persistence-unit name="jpa-h2-queryparams"
|
<persistence-unit name="jpa-h2-queryparams"
|
||||||
transaction-type="RESOURCE_LOCAL">
|
transaction-type="RESOURCE_LOCAL">
|
||||||
|
@ -11,20 +10,15 @@
|
||||||
<class>com.baeldung.jpa.queryparams.Employee</class>
|
<class>com.baeldung.jpa.queryparams.Employee</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="true" />
|
<property name="show_sql" value="true" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
<property name="jakarta.persistence.sql-load-script-source" value="queryparams.sql" />
|
||||||
<property name="javax.persistence.sql-load-script-source"
|
|
||||||
value="queryparams.sql" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -34,18 +28,14 @@
|
||||||
<class>com.baeldung.jpa.text.Exam</class>
|
<class>com.baeldung.jpa.text.Exam</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="true" />
|
<property name="show_sql" value="true" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -54,18 +44,14 @@
|
||||||
<class>com.baeldung.jpa.defaultvalues.User</class>
|
<class>com.baeldung.jpa.defaultvalues.User</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="true" />
|
<property name="show_sql" value="true" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -74,20 +60,15 @@
|
||||||
<class>com.baeldung.jpa.querytypes.UserEntity</class>
|
<class>com.baeldung.jpa.querytypes.UserEntity</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="true" />
|
<property name="show_sql" value="true" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
<property name="jakarta.persistence.sql-load-script-source" value="users.sql" />
|
||||||
<property name="javax.persistence.sql-load-script-source"
|
|
||||||
value="users.sql" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -96,20 +77,15 @@
|
||||||
<class>com.baeldung.jpa.projections.Product</class>
|
<class>com.baeldung.jpa.projections.Product</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="true" />
|
<property name="show_sql" value="true" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
<property name="jakarta.persistence.sql-load-script-source" value="products_jpa.sql" />
|
||||||
<property name="javax.persistence.sql-load-script-source"
|
|
||||||
value="products_jpa.sql" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -118,20 +94,15 @@
|
||||||
<class>com.baeldung.jpa.criteria.Item</class>
|
<class>com.baeldung.jpa.criteria.Item</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="true" />
|
<property name="show_sql" value="true" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
<property name="jakarta.persistence.sql-load-script-source" value="item.sql" />
|
||||||
<property name="javax.persistence.sql-load-script-source"
|
|
||||||
value="item.sql" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -147,19 +118,15 @@
|
||||||
|
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create" />
|
<property name="hibernate.hbm2ddl.auto" value="create" />
|
||||||
<property name="hibernate.hbm2ddl.import_files" value="multipletables.sql" />
|
<property name="hibernate.hbm2ddl.import_files" value="multipletables.sql" />
|
||||||
<property name="show_sql" value="true" />
|
<property name="show_sql" value="true" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -170,18 +137,14 @@
|
||||||
<class>com.baeldung.jpa.unrelated.entities.MultipleRecipe</class>
|
<class>com.baeldung.jpa.unrelated.entities.MultipleRecipe</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create" />
|
<property name="hibernate.hbm2ddl.auto" value="create" />
|
||||||
<property name="show_sql" value="true" />
|
<property name="show_sql" value="true" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -194,14 +157,11 @@
|
||||||
<class>com.baeldung.jpa.generateidvalue.User</class>
|
<class>com.baeldung.jpa.generateidvalue.User</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test;MODE=LEGACY" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="jakarta.persistence.sql-load-script-source" value="primary_key_generator.sql" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="javax.persistence.sql-load-script-source"
|
|
||||||
value="primary_key_generator.sql" />
|
|
||||||
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
|
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
|
||||||
<property name="eclipselink.ddl-generation.output-mode" value="database" />
|
<property name="eclipselink.ddl-generation.output-mode" value="database" />
|
||||||
<property name="eclipselink.weaving" value="static" />
|
<property name="eclipselink.weaving" value="static" />
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package com.baeldung.jpa.defaultvalues;
|
package com.baeldung.jpa.defaultvalues;
|
||||||
|
|
||||||
import com.baeldung.jpa.defaultvalues.User;
|
|
||||||
import com.baeldung.jpa.defaultvalues.UserRepository;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.baeldung.jpa.generateidvalue;
|
package com.baeldung.jpa.generateidvalue;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -27,12 +27,10 @@ public class PrimaryKeyUnitTest {
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.setName("TestName");
|
user.setName("TestName");
|
||||||
|
|
||||||
entityManager.getTransaction()
|
entityManager.getTransaction().begin();
|
||||||
.begin();
|
|
||||||
entityManager.persist(user);
|
entityManager.persist(user);
|
||||||
Assert.assertNull(user.getId());
|
Assert.assertNull(user.getId());
|
||||||
entityManager.getTransaction()
|
entityManager.getTransaction().commit();
|
||||||
.commit();
|
|
||||||
|
|
||||||
Long expectPrimaryKey = 1L;
|
Long expectPrimaryKey = 1L;
|
||||||
Assert.assertEquals(expectPrimaryKey, user.getId());
|
Assert.assertEquals(expectPrimaryKey, user.getId());
|
||||||
|
|
|
@ -2,9 +2,9 @@ package com.baeldung.jpa.multipletables;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
|
@ -5,19 +5,22 @@ import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.criterion.Order;
|
|
||||||
import org.hibernate.criterion.Projections;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||||
|
import jakarta.persistence.criteria.CriteriaQuery;
|
||||||
|
import jakarta.persistence.criteria.Path;
|
||||||
|
import jakarta.persistence.criteria.Root;
|
||||||
|
import jakarta.persistence.metamodel.SingularAttribute;
|
||||||
|
|
||||||
public class HibernateProjectionsIntegrationTest {
|
public class HibernateProjectionsIntegrationTest {
|
||||||
private static Session session;
|
private static Session session;
|
||||||
private static SessionFactory sessionFactory;
|
private static SessionFactory sessionFactory;
|
||||||
|
@ -61,11 +64,15 @@ public class HibernateProjectionsIntegrationTest {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Test
|
@Test
|
||||||
public void givenProductData_whenIdAndNameProjectionUsingCriteria_thenListOfObjectArrayReturned() {
|
public void givenProductData_whenIdAndNameProjectionUsingCriteria_thenListOfObjectArrayReturned() {
|
||||||
Criteria criteria = session.createCriteria(Product.class);
|
final CriteriaBuilder criteria = session.getCriteriaBuilder();
|
||||||
criteria = criteria.setProjection(Projections.projectionList()
|
final CriteriaQuery<Object[]> criteriaQuery = criteria.createQuery(Object[].class);
|
||||||
.add(Projections.id())
|
final Root<Product> root = criteriaQuery.from(Product.class);
|
||||||
.add(Projections.property("name")));
|
final SingularAttribute<Product, String> name = Product_.name;
|
||||||
List<Object[]> resultList = criteria.list();
|
final SingularAttribute<Product, Long> id = Product_.id;
|
||||||
|
final Path<String> nameProjection = root.get(name);
|
||||||
|
final Path<Long> idProjection = root.get(id);
|
||||||
|
criteriaQuery.multiselect(idProjection, nameProjection);
|
||||||
|
final List<Object[]> resultList = session.createQuery(criteriaQuery).getResultList();
|
||||||
|
|
||||||
assertNotNull(resultList);
|
assertNotNull(resultList);
|
||||||
assertEquals(4, resultList.size());
|
assertEquals(4, resultList.size());
|
||||||
|
@ -82,9 +89,13 @@ public class HibernateProjectionsIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenProductData_whenNameProjectionUsingCriteria_thenListOfStringReturned() {
|
public void givenProductData_whenNameProjectionUsingCriteria_thenListOfStringReturned() {
|
||||||
Criteria criteria = session.createCriteria(Product.class);
|
final CriteriaBuilder criteria = session.getCriteriaBuilder();
|
||||||
criteria = criteria.setProjection(Projections.property("name"));
|
final CriteriaQuery<String> criteriaQuery = criteria.createQuery(String.class);
|
||||||
List resultList = criteria.list();
|
final Root<Product> root = criteriaQuery.from(Product.class);
|
||||||
|
final SingularAttribute<Product, String> name = Product_.name;
|
||||||
|
final Path<String> nameProjection = root.get(name);
|
||||||
|
criteriaQuery.select(nameProjection);
|
||||||
|
final List<String> resultList = session.createQuery(criteriaQuery).getResultList();
|
||||||
|
|
||||||
assertNotNull(resultList);
|
assertNotNull(resultList);
|
||||||
assertEquals(4, resultList.size());
|
assertEquals(4, resultList.size());
|
||||||
|
@ -96,11 +107,12 @@ public class HibernateProjectionsIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenProductData_whenCountByCategoryUsingCriteria_thenOK() {
|
public void givenProductData_whenCountByCategoryUsingCriteria_thenOK() {
|
||||||
Criteria criteria = session.createCriteria(Product.class);
|
final CriteriaBuilder criteria = session.getCriteriaBuilder();
|
||||||
criteria = criteria.setProjection(Projections.projectionList()
|
final CriteriaQuery<Object[]> criteriaQuery = criteria.createQuery(Object[].class);
|
||||||
.add(Projections.groupProperty("category"))
|
final Root<Product> root = criteriaQuery.from(Product.class);
|
||||||
.add(Projections.rowCount()));
|
criteriaQuery.groupBy(root.get("category"));
|
||||||
List<Object[]> resultList = criteria.list();
|
criteriaQuery.multiselect(root.get("category"), criteria.count(root));
|
||||||
|
final List<Object[]> resultList = session.createQuery(criteriaQuery).getResultList();
|
||||||
|
|
||||||
assertNotNull(resultList);
|
assertNotNull(resultList);
|
||||||
assertEquals(3, resultList.size());
|
assertEquals(3, resultList.size());
|
||||||
|
@ -114,12 +126,13 @@ public class HibernateProjectionsIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenProductData_whenCountByCategoryWithAliasUsingCriteria_thenOK() {
|
public void givenProductData_whenCountByCategoryWithAliasUsingCriteria_thenOK() {
|
||||||
Criteria criteria = session.createCriteria(Product.class);
|
final CriteriaBuilder criteria = session.getCriteriaBuilder();
|
||||||
criteria = criteria.setProjection(Projections.projectionList()
|
final CriteriaQuery<Object[]> criteriaQuery = criteria.createQuery(Object[].class);
|
||||||
.add(Projections.groupProperty("category"))
|
final Root<Product> root = criteriaQuery.from(Product.class);
|
||||||
.add(Projections.alias(Projections.rowCount(), "count")));
|
criteriaQuery.groupBy(root.get("category"));
|
||||||
criteria.addOrder(Order.asc("count"));
|
criteriaQuery.multiselect(root.get("category"), criteria.count(root));
|
||||||
List<Object[]> resultList = criteria.list();
|
criteriaQuery.orderBy(criteria.asc(criteria.count(root)));
|
||||||
|
List<Object[]> resultList = session.createQuery(criteriaQuery).getResultList();
|
||||||
|
|
||||||
assertNotNull(resultList);
|
assertNotNull(resultList);
|
||||||
assertEquals(3, resultList.size());
|
assertEquals(3, resultList.size());
|
||||||
|
|
|
@ -3,14 +3,14 @@ package com.baeldung.jpa.queryparams;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
import javax.persistence.TypedQuery;
|
import jakarta.persistence.TypedQuery;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import jakarta.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.ParameterExpression;
|
import jakarta.persistence.criteria.ParameterExpression;
|
||||||
import javax.persistence.criteria.Root;
|
import jakarta.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.baeldung.jpa.text;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import javax.persistence.PersistenceException;
|
import jakarta.persistence.PersistenceException;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
package com.baeldung.jpa.unrelated.entities;
|
package com.baeldung.jpa.unrelated.entities;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
import com.querydsl.jpa.impl.JPAQuery;
|
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import com.querydsl.jpa.impl.JPAQuery;
|
||||||
|
|
||||||
public class UnrelatedEntitiesUnitTest {
|
public class UnrelatedEntitiesUnitTest {
|
||||||
private static EntityManagerFactory entityManagerFactory;
|
private static EntityManagerFactory entityManagerFactory;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
|
version="3.0"
|
||||||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
|
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd">
|
||||||
version="2.2">
|
|
||||||
|
|
||||||
<persistence-unit name="jpa-h2-queryparams"
|
<persistence-unit name="jpa-h2-queryparams"
|
||||||
transaction-type="RESOURCE_LOCAL">
|
transaction-type="RESOURCE_LOCAL">
|
||||||
|
@ -11,20 +10,15 @@
|
||||||
<class>com.baeldung.jpa.queryparams.Employee</class>
|
<class>com.baeldung.jpa.queryparams.Employee</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="false" />
|
<property name="show_sql" value="false" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
<property name="jakarta.persistence.sql-load-script-source" value="queryparams.sql" />
|
||||||
<property name="javax.persistence.sql-load-script-source"
|
|
||||||
value="queryparams.sql" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -34,18 +28,14 @@
|
||||||
<class>com.baeldung.jpa.text.Exam</class>
|
<class>com.baeldung.jpa.text.Exam</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="false" />
|
<property name="show_sql" value="false" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -54,18 +44,14 @@
|
||||||
<class>com.baeldung.jpa.defaultvalues.User</class>
|
<class>com.baeldung.jpa.defaultvalues.User</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="false" />
|
<property name="show_sql" value="false" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -74,20 +60,15 @@
|
||||||
<class>com.baeldung.jpa.querytypes.UserEntity</class>
|
<class>com.baeldung.jpa.querytypes.UserEntity</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="false" />
|
<property name="show_sql" value="false" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
<property name="jakarta.persistence.sql-load-script-source" value="users.sql" />
|
||||||
<property name="javax.persistence.sql-load-script-source"
|
|
||||||
value="users.sql" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -96,20 +77,15 @@
|
||||||
<class>com.baeldung.jpa.projections.Product</class>
|
<class>com.baeldung.jpa.projections.Product</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="false" />
|
<property name="show_sql" value="false" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
<property name="jakarta.persistence.sql-load-script-source" value="products_jpa.sql" />
|
||||||
<property name="javax.persistence.sql-load-script-source"
|
|
||||||
value="products_jpa.sql" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -118,20 +94,15 @@
|
||||||
<class>com.baeldung.jpa.criteria.Item</class>
|
<class>com.baeldung.jpa.criteria.Item</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="false" />
|
<property name="show_sql" value="false" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
<property name="jakarta.persistence.sql-load-script-source" value="item.sql" />
|
||||||
<property name="javax.persistence.sql-load-script-source"
|
|
||||||
value="item.sql" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -147,19 +118,15 @@
|
||||||
|
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create" />
|
<property name="hibernate.hbm2ddl.auto" value="create" />
|
||||||
<property name="hibernate.hbm2ddl.import_files" value="multipletables.sql" />
|
<property name="hibernate.hbm2ddl.import_files" value="multipletables.sql" />
|
||||||
<property name="show_sql" value="false" />
|
<property name="show_sql" value="false" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -170,18 +137,14 @@
|
||||||
<class>com.baeldung.jpa.unrelated.entities.MultipleRecipe</class>
|
<class>com.baeldung.jpa.unrelated.entities.MultipleRecipe</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create" />
|
<property name="hibernate.hbm2ddl.auto" value="create" />
|
||||||
<property name="show_sql" value="false" />
|
<property name="show_sql" value="false" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -194,14 +157,11 @@
|
||||||
<class>com.baeldung.jpa.generateidvalue.User</class>
|
<class>com.baeldung.jpa.generateidvalue.User</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test;MODE=LEGACY" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="jakarta.persistence.sql-load-script-source" value="primary_key_generator.sql" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="javax.persistence.sql-load-script-source"
|
|
||||||
value="primary_key_generator.sql" />
|
|
||||||
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
|
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
|
||||||
<property name="eclipselink.ddl-generation.output-mode" value="database" />
|
<property name="eclipselink.ddl-generation.output-mode" value="database" />
|
||||||
<property name="eclipselink.weaving" value="static" />
|
<property name="eclipselink.weaving" value="static" />
|
||||||
|
|
|
@ -14,32 +14,44 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
<artifactId>hibernate-core</artifactId>
|
<artifactId>hibernate-core</artifactId>
|
||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>jakarta.xml.bind</groupId>
|
||||||
|
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
<artifactId>hibernate-jpamodelgen</artifactId>
|
<artifactId>hibernate-jpamodelgen</artifactId>
|
||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>jakarta.xml.bind</groupId>
|
||||||
|
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<version>${h2.version}</version>
|
<version>${h2.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--Compile time JPA API -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.persistence</groupId>
|
|
||||||
<artifactId>javax.persistence-api</artifactId>
|
|
||||||
<version>${javax.persistence-api.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!--Runtime JPA implementation -->
|
<!--Runtime JPA implementation -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.persistence</groupId>
|
<groupId>org.eclipse.persistence</groupId>
|
||||||
<artifactId>eclipselink</artifactId>
|
<artifactId>eclipselink</artifactId>
|
||||||
<version>${eclipselink.version}</version>
|
<version>${eclipselink.version}</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>jakarta.xml.bind</groupId>
|
||||||
|
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
|
@ -47,6 +59,16 @@
|
||||||
<version>${postgresql.version}</version>
|
<version>${postgresql.version}</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.xml.bind</groupId>
|
||||||
|
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||||
|
<version>${jakarta.xml.bind-api.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.annotation</groupId>
|
||||||
|
<artifactId>javax.annotation-api</artifactId>
|
||||||
|
<version>${javax.annotation.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -102,12 +124,12 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<hibernate.version>5.4.0.Final</hibernate.version>
|
<eclipselink.version>4.0.1</eclipselink.version>
|
||||||
<eclipselink.version>2.7.4</eclipselink.version>
|
|
||||||
<javax.persistence-api.version>2.2</javax.persistence-api.version>
|
|
||||||
<maven-processor-plugin.version>3.3.3</maven-processor-plugin.version>
|
<maven-processor-plugin.version>3.3.3</maven-processor-plugin.version>
|
||||||
<build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
|
<build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
|
||||||
<h2.version>2.1.214</h2.version>
|
<h2.version>2.1.214</h2.version>
|
||||||
|
<jakarta.xml.bind-api.version>4.0.0</jakarta.xml.bind-api.version>
|
||||||
|
<javax.annotation.version>1.3.2</javax.annotation.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,9 +1,9 @@
|
||||||
package com.baeldung.jpa.basicannotation;
|
package com.baeldung.jpa.basicannotation;
|
||||||
|
|
||||||
import javax.persistence.Basic;
|
import jakarta.persistence.Basic;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Course {
|
public class Course {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.baeldung.jpa.convertdates;
|
package com.baeldung.jpa.convertdates;
|
||||||
|
|
||||||
import javax.persistence.AttributeConverter;
|
import jakarta.persistence.AttributeConverter;
|
||||||
import javax.persistence.Converter;
|
import jakarta.persistence.Converter;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.baeldung.jpa.datetime;
|
package com.baeldung.jpa.datetime;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.sql.Time;
|
import java.sql.Time;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.jpa.datetime;
|
package com.baeldung.jpa.datetime;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.sql.Time;
|
import java.sql.Time;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
|
|
@ -2,17 +2,17 @@ package com.baeldung.jpa.entity;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.EnumType;
|
import jakarta.persistence.EnumType;
|
||||||
import javax.persistence.Enumerated;
|
import jakarta.persistence.Enumerated;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import javax.persistence.Temporal;
|
import jakarta.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import jakarta.persistence.TemporalType;
|
||||||
import javax.persistence.Transient;
|
import jakarta.persistence.Transient;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="STUDENT")
|
@Table(name="STUDENT")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.jpa.entitygraph.model;
|
package com.baeldung.jpa.entitygraph.model;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Comment {
|
public class Comment {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.jpa.entitygraph.model;
|
package com.baeldung.jpa.entitygraph.model;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.baeldung.jpa.entitygraph.model;
|
package com.baeldung.jpa.entitygraph.model;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class User {
|
public class User {
|
||||||
|
|
|
@ -2,10 +2,10 @@ package com.baeldung.jpa.entitygraph.repo;
|
||||||
|
|
||||||
import com.baeldung.jpa.entitygraph.model.Post;
|
import com.baeldung.jpa.entitygraph.model.Post;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import jakarta.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Root;
|
import jakarta.persistence.criteria.Root;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public class PostRepository {
|
||||||
|
|
||||||
EntityGraph entityGraph = entityManager.getEntityGraph("post-entity-graph");
|
EntityGraph entityGraph = entityManager.getEntityGraph("post-entity-graph");
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
properties.put("javax.persistence.fetchgraph", entityGraph);
|
properties.put("jakarta.persistence.fetchgraph", entityGraph);
|
||||||
Post post = entityManager.find(Post.class, id, properties);
|
Post post = entityManager.find(Post.class, id, properties);
|
||||||
|
|
||||||
entityManager.close();
|
entityManager.close();
|
||||||
|
@ -51,7 +51,7 @@ public class PostRepository {
|
||||||
.addAttributeNodes("user");
|
.addAttributeNodes("user");
|
||||||
|
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
properties.put("javax.persistence.fetchgraph", entityGraph);
|
properties.put("jakarta.persistence.fetchgraph", entityGraph);
|
||||||
Post post = entityManager.find(Post.class, id, properties);
|
Post post = entityManager.find(Post.class, id, properties);
|
||||||
|
|
||||||
entityManager.close();
|
entityManager.close();
|
||||||
|
@ -64,7 +64,7 @@ public class PostRepository {
|
||||||
EntityGraph entityGraph = entityManager.getEntityGraph("post-entity-graph-with-comment-users");
|
EntityGraph entityGraph = entityManager.getEntityGraph("post-entity-graph-with-comment-users");
|
||||||
Post post = entityManager.createQuery("Select p from Post p where p.id=:id", Post.class)
|
Post post = entityManager.createQuery("Select p from Post p where p.id=:id", Post.class)
|
||||||
.setParameter("id", id)
|
.setParameter("id", id)
|
||||||
.setHint("javax.persistence.fetchgraph", entityGraph)
|
.setHint("jakarta.persistence.fetchgraph", entityGraph)
|
||||||
.getSingleResult();
|
.getSingleResult();
|
||||||
|
|
||||||
entityManager.close();
|
entityManager.close();
|
||||||
|
@ -80,7 +80,7 @@ public class PostRepository {
|
||||||
Root<Post> root = criteriaQuery.from(Post.class);
|
Root<Post> root = criteriaQuery.from(Post.class);
|
||||||
criteriaQuery.where(criteriaBuilder.equal(root.<Long>get("id"), id));
|
criteriaQuery.where(criteriaBuilder.equal(root.<Long>get("id"), id));
|
||||||
TypedQuery<Post> typedQuery = entityManager.createQuery(criteriaQuery);
|
TypedQuery<Post> typedQuery = entityManager.createQuery(criteriaQuery);
|
||||||
typedQuery.setHint("javax.persistence.loadgraph", entityGraph);
|
typedQuery.setHint("jakarta.persistence.loadgraph", entityGraph);
|
||||||
Post post = typedQuery.getSingleResult();
|
Post post = typedQuery.getSingleResult();
|
||||||
|
|
||||||
entityManager.close();
|
entityManager.close();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.jpa.enums;
|
package com.baeldung.jpa.enums;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Article {
|
public class Article {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.baeldung.jpa.enums;
|
package com.baeldung.jpa.enums;
|
||||||
|
|
||||||
import javax.persistence.AttributeConverter;
|
import jakarta.persistence.AttributeConverter;
|
||||||
import javax.persistence.Converter;
|
import jakarta.persistence.Converter;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Converter(autoApply = true)
|
@Converter(autoApply = true)
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package com.baeldung.jpa.model;
|
package com.baeldung.jpa.model;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.NamedStoredProcedureQueries;
|
import jakarta.persistence.NamedStoredProcedureQueries;
|
||||||
import javax.persistence.NamedStoredProcedureQuery;
|
import jakarta.persistence.NamedStoredProcedureQuery;
|
||||||
import javax.persistence.ParameterMode;
|
import jakarta.persistence.ParameterMode;
|
||||||
import javax.persistence.StoredProcedureParameter;
|
import jakarta.persistence.StoredProcedureParameter;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "CAR")
|
@Table(name = "CAR")
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.baeldung.jpa.primarykeys;
|
package com.baeldung.jpa.primarykeys;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.IdClass;
|
import jakarta.persistence.IdClass;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@IdClass(AccountId.class)
|
@IdClass(AccountId.class)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.baeldung.jpa.primarykeys;
|
package com.baeldung.jpa.primarykeys;
|
||||||
|
|
||||||
import javax.persistence.EmbeddedId;
|
import jakarta.persistence.EmbeddedId;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Book {
|
public class Book {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.baeldung.jpa.primarykeys;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import javax.persistence.Embeddable;
|
import jakarta.persistence.Embeddable;
|
||||||
|
|
||||||
@Embeddable
|
@Embeddable
|
||||||
public class BookId implements Serializable {
|
public class BookId implements Serializable {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.jpa.sqlresultsetmapping;
|
package com.baeldung.jpa.sqlresultsetmapping;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
|
||||||
@SqlResultSetMapping(
|
@SqlResultSetMapping(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.jpa.sqlresultsetmapping;
|
package com.baeldung.jpa.sqlresultsetmapping;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@SqlResultSetMappings(value = {
|
@SqlResultSetMappings(value = {
|
||||||
@SqlResultSetMapping(name = "ScheduleResult",
|
@SqlResultSetMapping(name = "ScheduleResult",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.jpa.stringcast;
|
package com.baeldung.jpa.stringcast;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@SqlResultSetMapping(name = "textQueryMapping", classes = {
|
@SqlResultSetMapping(name = "textQueryMapping", classes = {
|
||||||
@ConstructorResult(targetClass = Message.class, columns = {
|
@ConstructorResult(targetClass = Message.class, columns = {
|
||||||
|
|
|
@ -4,8 +4,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.Query;
|
import jakarta.persistence.Query;
|
||||||
|
|
||||||
public class QueryExecutor {
|
public class QueryExecutor {
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
|
version="3.0"
|
||||||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
|
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd">
|
||||||
version="2.2">
|
|
||||||
|
|
||||||
<persistence-unit name="java-jpa-scheduled-day">
|
<persistence-unit name="java-jpa-scheduled-day">
|
||||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||||
|
@ -12,18 +11,14 @@
|
||||||
<class>com.baeldung.jpa.basicannotation.Course</class>
|
<class>com.baeldung.jpa.basicannotation.Course</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test;MODE=LEGACY;INIT=RUNSCRIPT FROM 'classpath:database.sql'" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test;MODE=LEGACY;INIT=RUNSCRIPT FROM 'classpath:database.sql'" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<!--<property name="hibernate.hbm2ddl.auto" value="create-drop" /> -->
|
<!--<property name="hibernate.hbm2ddl.auto" value="create-drop" /> -->
|
||||||
<property name="show_sql" value="true" />
|
<property name="show_sql" value="true" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -34,18 +29,14 @@
|
||||||
<class>com.baeldung.jpa.enums.CategoryConverter</class>
|
<class>com.baeldung.jpa.enums.CategoryConverter</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test;MODE=LEGACY" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test;MODE=LEGACY" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="true" />
|
<property name="show_sql" value="true" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -54,39 +45,26 @@
|
||||||
<class>com.baeldung.jpa.model.Car</class>
|
<class>com.baeldung.jpa.model.Car</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
|
||||||
value="com.mysql.jdbc.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/baeldung" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="baeldung" />
|
||||||
value="jdbc:mysql://127.0.0.1:3306/baeldung" />
|
<property name="jakarta.persistence.jdbc.password" value="YourPassword" />
|
||||||
<property name="javax.persistence.jdbc.user"
|
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
|
||||||
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" />
|
<property name="hibernate.show_sql" value="true" />
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
<persistence-unit name="entity-graph-pu"
|
<persistence-unit name="entity-graph-pu" transaction-type="RESOURCE_LOCAL">
|
||||||
transaction-type="RESOURCE_LOCAL">
|
|
||||||
<class>com.baeldung.jpa.entitygraph.model.Post</class>
|
<class>com.baeldung.jpa.entitygraph.model.Post</class>
|
||||||
<class>com.baeldung.jpa.entitygraph.model.User</class>
|
<class>com.baeldung.jpa.entitygraph.model.User</class>
|
||||||
<class>com.baeldung.jpa.entitygraph.model.Comment</class>
|
<class>com.baeldung.jpa.entitygraph.model.Comment</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
|
|
||||||
<!--H2 -->
|
<!--H2 -->
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:entitygraphdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;NON_KEYWORDS=USER" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create" />
|
||||||
value="jdbc:h2:mem:entitygraphdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;NON_KEYWORDS=USER" />
|
<property name="jakarta.persistence.sql-load-script-source" value="data-init.sql" />
|
||||||
|
|
||||||
<property
|
|
||||||
name="javax.persistence.schema-generation.database.action"
|
|
||||||
value="drop-and-create" />
|
|
||||||
<property name="javax.persistence.sql-load-script-source"
|
|
||||||
value="data-init.sql" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
@ -96,17 +74,11 @@
|
||||||
<class>com.baeldung.jpa.datetime.JPA22DateTimeEntity</class>
|
<class>com.baeldung.jpa.datetime.JPA22DateTimeEntity</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.postgresql.Driver" />
|
||||||
value="org.postgresql.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/java8-datetime2" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="postgres" />
|
||||||
value="jdbc:postgresql://localhost:5432/java8-datetime2" />
|
<property name="jakarta.persistence.jdbc.password" value="postgres" />
|
||||||
<property name="javax.persistence.jdbc.user"
|
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create" />
|
||||||
value="postgres" />
|
|
||||||
<property name="javax.persistence.jdbc.password"
|
|
||||||
value="postgres" />
|
|
||||||
<property
|
|
||||||
name="javax.persistence.schema-generation.database.action"
|
|
||||||
value="drop-and-create" />
|
|
||||||
|
|
||||||
<!-- configure logging -->
|
<!-- configure logging -->
|
||||||
<property name="eclipselink.logging.level" value="INFO" />
|
<property name="eclipselink.logging.level" value="INFO" />
|
||||||
|
@ -124,18 +96,14 @@
|
||||||
<class>com.baeldung.jpa.primarykeys.AccountId</class>
|
<class>com.baeldung.jpa.primarykeys.AccountId</class>
|
||||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver"
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.url"
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
|
||||||
<property name="hibernate.dialect"
|
|
||||||
value="org.hibernate.dialect.H2Dialect" />
|
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="true" />
|
<property name="show_sql" value="true" />
|
||||||
<property name="hibernate.temp.use_jdbc_metadata_defaults"
|
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false" />
|
||||||
value="false" />
|
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.baeldung.jpa.basicannotation;
|
package com.baeldung.jpa.basicannotation;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
import javax.persistence.PersistenceException;
|
import jakarta.persistence.PersistenceException;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
|
@ -7,10 +7,10 @@ import java.time.ZoneId;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
import javax.persistence.TypedQuery;
|
import jakarta.persistence.TypedQuery;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
|
@ -3,11 +3,11 @@ package com.baeldung.jpa.enums;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.EntityTransaction;
|
import jakarta.persistence.EntityTransaction;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
import javax.persistence.TypedQuery;
|
import jakarta.persistence.TypedQuery;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -3,9 +3,9 @@ package com.baeldung.jpa.primarykeys;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
|
|
||||||
import com.baeldung.jpa.primarykeys.Account;
|
import com.baeldung.jpa.primarykeys.Account;
|
||||||
import com.baeldung.jpa.primarykeys.AccountId;
|
import com.baeldung.jpa.primarykeys.AccountId;
|
||||||
|
|
|
@ -4,10 +4,10 @@ import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
import javax.persistence.Query;
|
import jakarta.persistence.Query;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ public class SqlResultSetMappingUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenNamedQuery_thenMultipleEntityResult() {
|
public void whenNamedQuery_thenMultipleEntityResult() {
|
||||||
final Query query = em.createNativeQuery("SELECT e.id, e.name, d.id, d.employeeId, d.dayOfWeek "
|
final Query query = em.createNativeQuery("SELECT e.id as idEmployee, e.name, d.id as daysId, d.employeeId, d.dayOfWeek "
|
||||||
+ " FROM employee e, schedule_days d "
|
+ " FROM employee e, schedule_days d "
|
||||||
+ " WHERE e.id = d.employeeId", "EmployeeScheduleResults");
|
+ " WHERE e.id = d.employeeId", "EmployeeScheduleResults");
|
||||||
List<Object[]> results = query.getResultList();
|
List<Object[]> results = query.getResultList();
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package com.baeldung.jpa.storedprocedure;
|
package com.baeldung.jpa.storedprocedure;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.EntityTransaction;
|
import jakarta.persistence.EntityTransaction;
|
||||||
import javax.persistence.ParameterMode;
|
import jakarta.persistence.ParameterMode;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
import javax.persistence.StoredProcedureQuery;
|
import jakarta.persistence.StoredProcedureQuery;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.baeldung.jpa.stringcast;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
|
version="3.0"
|
||||||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
|
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd">
|
||||||
version="2.1">
|
|
||||||
|
|
||||||
<persistence-unit name="jpa-db">
|
<persistence-unit name="jpa-db">
|
||||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||||
<class>com.baeldung.jpa.model.Car</class>
|
<class>com.baeldung.jpa.model.Car</class>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
|
<property name="jakarta.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
|
||||||
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/baeldung" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/baeldung" />
|
||||||
<property name="javax.persistence.jdbc.user" value="baeldung" />
|
<property name="jakarta.persistence.jdbc.user" value="baeldung" />
|
||||||
<property name="javax.persistence.jdbc.password" value="YourPassword" />
|
<property name="jakarta.persistence.jdbc.password" value="YourPassword" />
|
||||||
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
|
||||||
<property name="hibernate.show_sql" value="false" />
|
<property name="hibernate.show_sql" value="false" />
|
||||||
</properties>
|
</properties>
|
||||||
|
@ -22,10 +21,10 @@
|
||||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||||
<class>com.baeldung.jpa.stringcast.Message</class>
|
<class>com.baeldung.jpa.stringcast.Message</class>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
|
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||||
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||||
<property name="javax.persistence.jdbc.user" value="sa" />
|
<property name="jakarta.persistence.jdbc.user" value="sa" />
|
||||||
<property name="javax.persistence.jdbc.password" value="" />
|
<property name="jakarta.persistence.jdbc.password" value="" />
|
||||||
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||||
<property name="show_sql" value="false"/>
|
<property name="show_sql" value="false"/>
|
||||||
|
|
|
@ -40,6 +40,16 @@
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<version>${maven.war-plugin.version}</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${maven.compiler-plugin.version}</version>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>net.wasdev.wlp.maven.plugins</groupId>
|
<groupId>net.wasdev.wlp.maven.plugins</groupId>
|
||||||
<artifactId>liberty-maven-plugin</artifactId>
|
<artifactId>liberty-maven-plugin</artifactId>
|
||||||
|
@ -80,7 +90,9 @@
|
||||||
<properties>
|
<properties>
|
||||||
<liberty-maven-plugin.version>2.4.2</liberty-maven-plugin.version>
|
<liberty-maven-plugin.version>2.4.2</liberty-maven-plugin.version>
|
||||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
<javaee-web-api.version>8.0</javaee-web-api.version>
|
<javaee-web-api.version>8.0.1</javaee-web-api.version>
|
||||||
|
<maven.war-plugin.version>3.3.1</maven.war-plugin.version>
|
||||||
|
<maven.compiler-plugin.version>3.8.1</maven.compiler-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -35,27 +35,26 @@
|
||||||
<module>hibernate-queries</module>
|
<module>hibernate-queries</module>
|
||||||
<module>hibernate-enterprise</module>
|
<module>hibernate-enterprise</module>
|
||||||
<module>influxdb</module>
|
<module>influxdb</module>
|
||||||
<!-- <module>java-cassandra</module> FAILED -->
|
|
||||||
<module>java-cockroachdb</module>
|
<module>java-cockroachdb</module>
|
||||||
<module>java-jdbi</module>
|
<module>java-jdbi</module>
|
||||||
<!-- <module>java-jpa</module> FAILED --> <!-- long running -->
|
<module>java-jpa</module> <!-- long running -->
|
||||||
<!-- <module>java-jpa-2</module> FAILED --> <!-- long running -->
|
<module>java-jpa-2</module>
|
||||||
<module>java-jpa-3</module>
|
<module>java-jpa-3</module>
|
||||||
<!-- enable it when persistence-modules is migrated to JDK9+ -->
|
<!-- enable it when persistence-modules is migrated to JDK9+ -->
|
||||||
<!-- <module>java-mongodb</module>--> <!-- long running -->
|
<!-- <module>java-mongodb</module>--> <!-- long running -->
|
||||||
<module>java-mongodb-2</module> <!-- long running -->
|
<module>java-mongodb-2</module> <!-- long running -->
|
||||||
<module>java-mongodb-3</module> <!-- long running -->
|
<module>java-mongodb-3</module> <!-- long running -->
|
||||||
<module>java-mongodb-queries</module> <!-- long running -->
|
<module>java-mongodb-queries</module> <!-- long running -->
|
||||||
<!-- <module>jnosql</module> FAILED --> <!-- long running -->
|
<module>jnosql</module> <!-- long running -->
|
||||||
<module>jooq</module>
|
<module>jooq</module>
|
||||||
<module>jpa-hibernate-cascade-type</module>
|
<module>jpa-hibernate-cascade-type</module>
|
||||||
<module>liquibase</module>
|
<module>liquibase</module>
|
||||||
<module>orientdb</module>
|
<module>orientdb</module>
|
||||||
<module>persistence-libraries</module>
|
<module>persistence-libraries</module>
|
||||||
<!-- <module>querydsl</module> FAILED -->
|
<module>querydsl</module>
|
||||||
<!-- <module>r2dbc</module> FAILED -->
|
<module>r2dbc</module>
|
||||||
<module>read-only-transactions</module>
|
<module>read-only-transactions</module>
|
||||||
<!-- <module>redis</module> FAILED -->
|
<module>redis</module>
|
||||||
<!-- <module>sirix</module> --> <!-- We haven't upgraded to java 11. Fixing in BAEL-10841 -->
|
<!-- <module>sirix</module> --> <!-- We haven't upgraded to java 11. Fixing in BAEL-10841 -->
|
||||||
<module>solr</module>
|
<module>solr</module>
|
||||||
<module>spring-boot-persistence-2</module>
|
<module>spring-boot-persistence-2</module>
|
||||||
|
|
|
@ -19,11 +19,13 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.querydsl</groupId>
|
<groupId>com.querydsl</groupId>
|
||||||
<artifactId>querydsl-jpa</artifactId>
|
<artifactId>querydsl-jpa</artifactId>
|
||||||
|
<classifier>jakarta</classifier>
|
||||||
<version>${querydsl.version}</version>
|
<version>${querydsl.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.querydsl</groupId>
|
<groupId>com.querydsl</groupId>
|
||||||
<artifactId>querydsl-apt</artifactId>
|
<artifactId>querydsl-apt</artifactId>
|
||||||
|
<classifier>jakarta</classifier>
|
||||||
<version>${querydsl.version}</version>
|
<version>${querydsl.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -34,12 +36,6 @@
|
||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.hibernate.javax.persistence</groupId>
|
|
||||||
<artifactId>hibernate-jpa-2.1-api</artifactId>
|
|
||||||
<version>${hibernate-jpa.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-dbcp</groupId>
|
<groupId>commons-dbcp</groupId>
|
||||||
<artifactId>commons-dbcp</artifactId>
|
<artifactId>commons-dbcp</artifactId>
|
||||||
|
@ -106,8 +102,6 @@
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${java.version}</source>
|
|
||||||
<target>${java.version}</target>
|
|
||||||
<compilerArgument>-proc:none</compilerArgument>
|
<compilerArgument>-proc:none</compilerArgument>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
@ -132,10 +126,8 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<spring.version>4.3.4.RELEASE</spring.version>
|
<spring.version>6.0.6</spring.version>
|
||||||
<hibernate.version>5.2.5.Final</hibernate.version>
|
<querydsl.version>5.0.0</querydsl.version>
|
||||||
<hibernate-jpa.version>1.0.0.Final</hibernate-jpa.version>
|
|
||||||
<querydsl.version>4.1.4</querydsl.version>
|
|
||||||
<commons-pool.version>1.6</commons-pool.version>
|
<commons-pool.version>1.6</commons-pool.version>
|
||||||
<commons-dbcp.version>1.4</commons-dbcp.version>
|
<commons-dbcp.version>1.4</commons-dbcp.version>
|
||||||
<apt-maven-plugin.version>1.1.3</apt-maven-plugin.version>
|
<apt-maven-plugin.version>1.1.3</apt-maven-plugin.version>
|
||||||
|
|
|
@ -3,14 +3,18 @@ package com.baeldung.dao;
|
||||||
import com.baeldung.entity.Person;
|
import com.baeldung.entity.Person;
|
||||||
import com.baeldung.entity.QPerson;
|
import com.baeldung.entity.QPerson;
|
||||||
import com.querydsl.core.group.GroupBy;
|
import com.querydsl.core.group.GroupBy;
|
||||||
|
import com.querydsl.jpa.JPQLTemplates;
|
||||||
import com.querydsl.jpa.impl.JPAQuery;
|
import com.querydsl.jpa.impl.JPAQuery;
|
||||||
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.PersistenceContext;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.PersistenceContext;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public class PersonDaoImpl implements PersonDao {
|
public class PersonDaoImpl implements PersonDao {
|
||||||
|
|
||||||
|
@ -57,7 +61,7 @@ public class PersonDaoImpl implements PersonDao {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Integer> findMaxAgeByName() {
|
public Map<String, Integer> findMaxAgeByName() {
|
||||||
final JPAQuery<Person> query = new JPAQuery<>(em);
|
final JPAQueryFactory query = new JPAQueryFactory(JPQLTemplates.DEFAULT, em);
|
||||||
final QPerson person = QPerson.person;
|
final QPerson person = QPerson.person;
|
||||||
|
|
||||||
return query.from(person).transform(GroupBy.groupBy(person.firstname).as(GroupBy.max(person.age)));
|
return query.from(person).transform(GroupBy.groupBy(person.firstname).as(GroupBy.max(person.age)));
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.baeldung.entity;
|
package com.baeldung.entity;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Person {
|
public class Person {
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
*/
|
*/
|
||||||
package com.baeldung.querydsl.intro.entities;
|
package com.baeldung.querydsl.intro.entities;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class BlogPost {
|
public class BlogPost {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package com.baeldung.querydsl.intro.entities;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class User {
|
public class User {
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
|
version="3.0"
|
||||||
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
|
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd">
|
||||||
version="2.0">
|
|
||||||
|
|
||||||
<!-- PersistenceUnit for datastore -->
|
<!-- PersistenceUnit for datastore -->
|
||||||
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
|
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
|
||||||
|
|
|
@ -6,9 +6,9 @@ import com.baeldung.entity.Person;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.annotation.Rollback;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.transaction.TransactionConfiguration;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
@ -16,7 +16,7 @@ import junit.framework.Assert;
|
||||||
@ContextConfiguration("/test-context.xml")
|
@ContextConfiguration("/test-context.xml")
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@Transactional
|
@Transactional
|
||||||
@TransactionConfiguration(defaultRollback = true)
|
@Rollback
|
||||||
public class PersonDaoIntegrationTest {
|
public class PersonDaoIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -14,9 +14,9 @@ import com.querydsl.jpa.JPAExpressions;
|
||||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import jakarta.persistence.Persistence;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
|
@ -89,9 +89,9 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<flyway.core.version>9.14.1</flyway.core.version>
|
<flyway.core.version>9.16.0</flyway.core.version>
|
||||||
<jdbc.postgresql.version>42.5.2</jdbc.postgresql.version>
|
<jdbc.postgresql.version>42.5.4</jdbc.postgresql.version>
|
||||||
<r2dbc.postgresql.version>1.0.0.RELEASE</r2dbc.postgresql.version>
|
<r2dbc.postgresql.version>1.0.1.RELEASE</r2dbc.postgresql.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -30,8 +30,7 @@ public class DatasourceConfig {
|
||||||
ob = ob.option(PASSWORD, properties.getPassword());
|
ob = ob.option(PASSWORD, properties.getPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionFactory cf = ConnectionFactories.get(ob.build());
|
return ConnectionFactories.get(ob.build());
|
||||||
return cf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ spring:
|
||||||
flyway:
|
flyway:
|
||||||
url: jdbc:postgresql://localhost:8082/flyway-test-db
|
url: jdbc:postgresql://localhost:8082/flyway-test-db
|
||||||
locations: classpath:db/postgres/migration
|
locations: classpath:db/postgres/migration
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
# R2DBC URL
|
# R2DBC URL
|
||||||
r2dbc:
|
r2dbc:
|
||||||
url: r2dbc:h2:mem://./testdb
|
url: r2dbc:h2:mem://./testdb
|
||||||
|
|
|
@ -55,9 +55,7 @@ public class R2dbcExampleApplicationIntegrationTest {
|
||||||
.expectStatus()
|
.expectStatus()
|
||||||
.isOk()
|
.isOk()
|
||||||
.expectBody(Account.class)
|
.expectBody(Account.class)
|
||||||
.value((acc) -> {
|
.value((acc) -> assertThat(acc.getId(),is(1L)));
|
||||||
assertThat(acc.getId(),is(1l));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -71,9 +69,7 @@ public class R2dbcExampleApplicationIntegrationTest {
|
||||||
.expectStatus()
|
.expectStatus()
|
||||||
.isOk()
|
.isOk()
|
||||||
.expectBody(List.class)
|
.expectBody(List.class)
|
||||||
.value((accounts) -> {
|
.value((accounts) -> assertThat(accounts.size(),not(is(0))));
|
||||||
assertThat(accounts.size(),not(is(0)));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,9 +85,7 @@ public class R2dbcExampleApplicationIntegrationTest {
|
||||||
.expectStatus()
|
.expectStatus()
|
||||||
.is2xxSuccessful()
|
.is2xxSuccessful()
|
||||||
.expectBody(Account.class)
|
.expectBody(Account.class)
|
||||||
.value((acc) -> {
|
.value((acc) -> assertThat(acc.getId(),is(notNullValue())));
|
||||||
assertThat(acc.getId(),is(notNullValue()));
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,9 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<embedded-redis.version>0.6</embedded-redis.version>
|
<embedded-redis.version>0.6</embedded-redis.version>
|
||||||
<redisson.version>3.13.1</redisson.version>
|
<redisson.version>3.20.0</redisson.version>
|
||||||
<jedis.version>3.3.0</jedis.version>
|
<jedis.version>4.3.2</jedis.version>
|
||||||
<epoll.version>4.1.50.Final</epoll.version>
|
<epoll.version>4.1.90.Final</epoll.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -102,18 +102,18 @@ public class RedisClient {
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> zrange(final String key, final long start, final long stop) {
|
public List<String> zrange(final String key, final long start, final long stop) {
|
||||||
try (Jedis jedis = jedisPool.getResource()) {
|
try (Jedis jedis = jedisPool.getResource()) {
|
||||||
return jedis.zrange(key, start, stop);
|
return jedis.zrange(key, start, stop);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error("Exception caught in zrange", ex);
|
log.error("Exception caught in zrange", ex);
|
||||||
}
|
}
|
||||||
return new HashSet<String>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String mset(final HashMap<String, String> keysValues) {
|
public String mset(final HashMap<String, String> keysValues) {
|
||||||
try (Jedis jedis = jedisPool.getResource()) {
|
try (Jedis jedis = jedisPool.getResource()) {
|
||||||
ArrayList<String> keysValuesArrayList = new ArrayList<String>();
|
ArrayList<String> keysValuesArrayList = new ArrayList<>();
|
||||||
keysValues.forEach((key, value) -> {
|
keysValues.forEach((key, value) -> {
|
||||||
keysValuesArrayList.add(key);
|
keysValuesArrayList.add(key);
|
||||||
keysValuesArrayList.add(value);
|
keysValuesArrayList.add(value);
|
||||||
|
|
|
@ -5,8 +5,8 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisPool;
|
import redis.clients.jedis.JedisPool;
|
||||||
import redis.clients.jedis.ScanParams;
|
import redis.clients.jedis.params.ScanParams;
|
||||||
import redis.clients.jedis.ScanResult;
|
import redis.clients.jedis.resps.ScanResult;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.baeldung.redis_scan.strategy;
|
package com.baeldung.redis_scan.strategy;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.ScanParams;
|
import redis.clients.jedis.params.ScanParams;
|
||||||
import redis.clients.jedis.ScanResult;
|
import redis.clients.jedis.resps.ScanResult;
|
||||||
|
|
||||||
public interface ScanStrategy<T> {
|
public interface ScanStrategy<T> {
|
||||||
ScanResult<T> scan(Jedis jedis, String cursor, ScanParams scanParams);
|
ScanResult<T> scan(Jedis jedis, String cursor, ScanParams scanParams);
|
||||||
|
|
|
@ -2,8 +2,8 @@ package com.baeldung.redis_scan.strategy.impl;
|
||||||
|
|
||||||
import com.baeldung.redis_scan.strategy.ScanStrategy;
|
import com.baeldung.redis_scan.strategy.ScanStrategy;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.ScanParams;
|
import redis.clients.jedis.params.ScanParams;
|
||||||
import redis.clients.jedis.ScanResult;
|
import redis.clients.jedis.resps.ScanResult;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
|
@ -2,8 +2,8 @@ package com.baeldung.redis_scan.strategy.impl;
|
||||||
|
|
||||||
import com.baeldung.redis_scan.strategy.ScanStrategy;
|
import com.baeldung.redis_scan.strategy.ScanStrategy;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.ScanParams;
|
import redis.clients.jedis.params.ScanParams;
|
||||||
import redis.clients.jedis.ScanResult;
|
import redis.clients.jedis.resps.ScanResult;
|
||||||
|
|
||||||
public class Scan implements ScanStrategy<String> {
|
public class Scan implements ScanStrategy<String> {
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ package com.baeldung.redis_scan.strategy.impl;
|
||||||
|
|
||||||
import com.baeldung.redis_scan.strategy.ScanStrategy;
|
import com.baeldung.redis_scan.strategy.ScanStrategy;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.ScanParams;
|
import redis.clients.jedis.params.ScanParams;
|
||||||
import redis.clients.jedis.ScanResult;
|
import redis.clients.jedis.resps.ScanResult;
|
||||||
|
|
||||||
public class Sscan implements ScanStrategy<String> {
|
public class Sscan implements ScanStrategy<String> {
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,9 @@ package com.baeldung.redis_scan.strategy.impl;
|
||||||
|
|
||||||
import com.baeldung.redis_scan.strategy.ScanStrategy;
|
import com.baeldung.redis_scan.strategy.ScanStrategy;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.ScanParams;
|
import redis.clients.jedis.params.ScanParams;
|
||||||
import redis.clients.jedis.ScanResult;
|
import redis.clients.jedis.resps.ScanResult;
|
||||||
import redis.clients.jedis.Tuple;
|
import redis.clients.jedis.resps.Tuple;
|
||||||
|
|
||||||
public class Zscan implements ScanStrategy<Tuple> {
|
public class Zscan implements ScanStrategy<Tuple> {
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -35,7 +36,10 @@ public class JedisIntegrationTest {
|
||||||
port = s.getLocalPort();
|
port = s.getLocalPort();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
redisServer = new RedisServer(port);
|
redisServer = RedisServer.builder()
|
||||||
|
.port(port)
|
||||||
|
.setting("maxheap 128M")
|
||||||
|
.build();
|
||||||
redisServer.start();
|
redisServer.start();
|
||||||
|
|
||||||
// Configure JEDIS
|
// Configure JEDIS
|
||||||
|
@ -148,7 +152,7 @@ public class JedisIntegrationTest {
|
||||||
jedis.zadd(key, playerScore.getValue(), playerScore.getKey());
|
jedis.zadd(key, playerScore.getValue(), playerScore.getKey());
|
||||||
});
|
});
|
||||||
|
|
||||||
Set<String> players = jedis.zrevrange(key, 0, 1);
|
List<String> players = jedis.zrevrange(key, 0, 1);
|
||||||
Assert.assertEquals("PlayerThree", players.iterator().next());
|
Assert.assertEquals("PlayerThree", players.iterator().next());
|
||||||
|
|
||||||
long rank = jedis.zrevrank(key, "PlayerOne");
|
long rank = jedis.zrevrank(key, "PlayerOne");
|
||||||
|
@ -184,7 +188,7 @@ public class JedisIntegrationTest {
|
||||||
p.zadd("ranking", 126, userOneId);
|
p.zadd("ranking", 126, userOneId);
|
||||||
p.zadd("ranking", 325, userTwoId);
|
p.zadd("ranking", 325, userTwoId);
|
||||||
Response<Boolean> pipeExists = p.sismember("searched#" + userOneId, "paris");
|
Response<Boolean> pipeExists = p.sismember("searched#" + userOneId, "paris");
|
||||||
Response<Set<String>> pipeRanking = p.zrange("ranking", 0, -1);
|
Response<List<String>> pipeRanking = p.zrange("ranking", 0, -1);
|
||||||
p.sync();
|
p.sync();
|
||||||
|
|
||||||
Assert.assertTrue(pipeExists.get());
|
Assert.assertTrue(pipeExists.get());
|
||||||
|
|
|
@ -32,7 +32,10 @@ public class RedissonConfigurationIntegrationTest {
|
||||||
port = s.getLocalPort();
|
port = s.getLocalPort();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
redisServer = new RedisServer(port);
|
redisServer = RedisServer.builder()
|
||||||
|
.port(port)
|
||||||
|
.setting("maxheap 128M")
|
||||||
|
.build();
|
||||||
redisServer.start();
|
redisServer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,11 @@ public class RedissonIntegrationTest {
|
||||||
private static RedissonClient client;
|
private static RedissonClient client;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws IOException {
|
public static void setUp() {
|
||||||
redisServer = new RedisServer(6379);
|
redisServer = RedisServer.builder()
|
||||||
|
.port(6379)
|
||||||
|
.setting("maxheap 128M")
|
||||||
|
.build();
|
||||||
redisServer.start();
|
redisServer.start();
|
||||||
client = Redisson.create();
|
client = Redisson.create();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,10 @@ public class DeleteEverythingInRedisIntegrationTest {
|
||||||
port = s.getLocalPort();
|
port = s.getLocalPort();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
redisServer = new RedisServer(port);
|
redisServer = RedisServer.builder()
|
||||||
|
.port(port)
|
||||||
|
.setting("maxheap 128M")
|
||||||
|
.build();
|
||||||
redisServer.start();
|
redisServer.start();
|
||||||
|
|
||||||
// Configure JEDIS
|
// Configure JEDIS
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -24,7 +25,10 @@ public class NaiveApproachIntegrationTest {
|
||||||
port = s.getLocalPort();
|
port = s.getLocalPort();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
redisServer = new RedisServer(port);
|
redisServer = RedisServer.builder()
|
||||||
|
.port(port)
|
||||||
|
.setting("maxheap 128M")
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
@ -50,7 +54,7 @@ public class NaiveApproachIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKeys() {
|
public void testKeys() {
|
||||||
HashMap<String, String> keyValues = new HashMap<String, String>();
|
HashMap<String, String> keyValues = new HashMap<>();
|
||||||
keyValues.put("balls:cricket", "160");
|
keyValues.put("balls:cricket", "160");
|
||||||
keyValues.put("balls:football", "450");
|
keyValues.put("balls:football", "450");
|
||||||
keyValues.put("balls:volleyball", "270");
|
keyValues.put("balls:volleyball", "270");
|
||||||
|
@ -62,7 +66,7 @@ public class NaiveApproachIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSmembers() {
|
public void testSmembers() {
|
||||||
HashSet<String> setMembers = new HashSet<String>();
|
HashSet<String> setMembers = new HashSet<>();
|
||||||
setMembers.add("cricket_160");
|
setMembers.add("cricket_160");
|
||||||
setMembers.add("football_450");
|
setMembers.add("football_450");
|
||||||
setMembers.add("volleyball_270");
|
setMembers.add("volleyball_270");
|
||||||
|
@ -73,7 +77,7 @@ public class NaiveApproachIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHgetAll() {
|
public void testHgetAll() {
|
||||||
HashMap<String, String> keyValues = new HashMap<String, String>();
|
HashMap<String, String> keyValues = new HashMap<>();
|
||||||
keyValues.put("balls:cricket", "160");
|
keyValues.put("balls:cricket", "160");
|
||||||
keyValues.put("balls:football", "450");
|
keyValues.put("balls:football", "450");
|
||||||
keyValues.put("balls:volleyball", "270");
|
keyValues.put("balls:volleyball", "270");
|
||||||
|
@ -84,12 +88,12 @@ public class NaiveApproachIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testZRange() {
|
public void testZRange() {
|
||||||
HashMap<String, Double> scoreMembers = new HashMap<String, Double>();
|
HashMap<String, Double> scoreMembers = new HashMap<>();
|
||||||
scoreMembers.put("cricket", (double) 160);
|
scoreMembers.put("cricket", (double) 160);
|
||||||
scoreMembers.put("football", (double) 450);
|
scoreMembers.put("football", (double) 450);
|
||||||
scoreMembers.put("volleyball", (double) 270);
|
scoreMembers.put("volleyball", (double) 270);
|
||||||
redisClient.zadd("balls", scoreMembers);
|
redisClient.zadd("balls", scoreMembers);
|
||||||
Set<String> readSetMembers = redisClient.zrange("balls", 0, -1);
|
List<String> readSetMembers = redisClient.zrange("balls", 0, -1);
|
||||||
|
|
||||||
Assert.assertEquals(readSetMembers.size(), scoreMembers.size());
|
Assert.assertEquals(readSetMembers.size(), scoreMembers.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import com.baeldung.redis_scan.strategy.impl.Scan;
|
||||||
import com.baeldung.redis_scan.strategy.impl.Sscan;
|
import com.baeldung.redis_scan.strategy.impl.Sscan;
|
||||||
import com.baeldung.redis_scan.strategy.impl.Zscan;
|
import com.baeldung.redis_scan.strategy.impl.Zscan;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import redis.clients.jedis.Tuple;
|
import redis.clients.jedis.resps.Tuple;
|
||||||
import redis.embedded.RedisServer;
|
import redis.embedded.RedisServer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -31,7 +31,10 @@ public class ScanStrategyIntegrationTest {
|
||||||
port = s.getLocalPort();
|
port = s.getLocalPort();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
redisServer = new RedisServer(port);
|
redisServer = RedisServer.builder()
|
||||||
|
.port(port)
|
||||||
|
.setting("maxheap 128M")
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
@ -57,7 +60,7 @@ public class ScanStrategyIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScanStrategy() {
|
public void testScanStrategy() {
|
||||||
HashMap<String, String> keyValues = new HashMap<String, String>();
|
HashMap<String, String> keyValues = new HashMap<>();
|
||||||
keyValues.put("balls:cricket", "160");
|
keyValues.put("balls:cricket", "160");
|
||||||
keyValues.put("balls:football", "450");
|
keyValues.put("balls:football", "450");
|
||||||
keyValues.put("balls:volleyball", "270");
|
keyValues.put("balls:volleyball", "270");
|
||||||
|
@ -66,7 +69,7 @@ public class ScanStrategyIntegrationTest {
|
||||||
ScanStrategy<String> scanStrategy = new Scan();
|
ScanStrategy<String> scanStrategy = new Scan();
|
||||||
int iterationCount = 2;
|
int iterationCount = 2;
|
||||||
RedisIterator iterator = redisClient.iterator(iterationCount, "ball*", scanStrategy);
|
RedisIterator iterator = redisClient.iterator(iterationCount, "ball*", scanStrategy);
|
||||||
List<String> results = new LinkedList<String>();
|
List<String> results = new LinkedList<>();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
results.addAll(iterator.next());
|
results.addAll(iterator.next());
|
||||||
}
|
}
|
||||||
|
@ -84,7 +87,7 @@ public class ScanStrategyIntegrationTest {
|
||||||
Sscan scanStrategy = new Sscan("balls");
|
Sscan scanStrategy = new Sscan("balls");
|
||||||
int iterationCount = 2;
|
int iterationCount = 2;
|
||||||
RedisIterator iterator = redisClient.iterator(iterationCount, "*", scanStrategy);
|
RedisIterator iterator = redisClient.iterator(iterationCount, "*", scanStrategy);
|
||||||
List<String> results = new LinkedList<String>();
|
List<String> results = new LinkedList<>();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
results.addAll(iterator.next());
|
results.addAll(iterator.next());
|
||||||
}
|
}
|
||||||
|
@ -93,7 +96,7 @@ public class ScanStrategyIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHscanStrategy() {
|
public void testHscanStrategy() {
|
||||||
HashMap<String, String> hash = new HashMap<String, String>();
|
HashMap<String, String> hash = new HashMap<>();
|
||||||
hash.put("cricket", "160");
|
hash.put("cricket", "160");
|
||||||
hash.put("football", "450");
|
hash.put("football", "450");
|
||||||
hash.put("volleyball", "270");
|
hash.put("volleyball", "270");
|
||||||
|
@ -102,7 +105,7 @@ public class ScanStrategyIntegrationTest {
|
||||||
Hscan scanStrategy = new Hscan("balls");
|
Hscan scanStrategy = new Hscan("balls");
|
||||||
int iterationCount = 2;
|
int iterationCount = 2;
|
||||||
RedisIterator iterator = redisClient.iterator(iterationCount, "*", scanStrategy);
|
RedisIterator iterator = redisClient.iterator(iterationCount, "*", scanStrategy);
|
||||||
List<Map.Entry<String, String>> results = new LinkedList<Map.Entry<String, String>>();
|
List<Map.Entry<String, String>> results = new LinkedList<>();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
results.addAll(iterator.next());
|
results.addAll(iterator.next());
|
||||||
}
|
}
|
||||||
|
@ -111,7 +114,7 @@ public class ScanStrategyIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testZscanStrategy() {
|
public void testZscanStrategy() {
|
||||||
HashMap<String, Double> memberScores = new HashMap<String, Double>();
|
HashMap<String, Double> memberScores = new HashMap<>();
|
||||||
memberScores.put("cricket", (double) 160);
|
memberScores.put("cricket", (double) 160);
|
||||||
memberScores.put("football", (double) 450);
|
memberScores.put("football", (double) 450);
|
||||||
memberScores.put("volleyball", (double) 270);
|
memberScores.put("volleyball", (double) 270);
|
||||||
|
@ -120,7 +123,7 @@ public class ScanStrategyIntegrationTest {
|
||||||
Zscan scanStrategy = new Zscan("balls");
|
Zscan scanStrategy = new Zscan("balls");
|
||||||
int iterationCount = 2;
|
int iterationCount = 2;
|
||||||
RedisIterator iterator = redisClient.iterator(iterationCount, "*", scanStrategy);
|
RedisIterator iterator = redisClient.iterator(iterationCount, "*", scanStrategy);
|
||||||
List<Tuple> results = new LinkedList<Tuple>();
|
List<Tuple> results = new LinkedList<>();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
results.addAll(iterator.next());
|
results.addAll(iterator.next());
|
||||||
}
|
}
|
||||||
|
|
10
pom.xml
10
pom.xml
|
@ -365,8 +365,9 @@
|
||||||
|
|
||||||
<module>muleesb</module>
|
<module>muleesb</module>
|
||||||
|
|
||||||
<module>persistence-modules/deltaspike</module> <!-- delta spike it doesn't yet the jakarta API-->
|
<module>persistence-modules/deltaspike</module> <!-- delta spike it doesn't support yet the jakarta API-->
|
||||||
<module>persistence-modules/hibernate-ogm</module> <!-- hibernate-ogm wasn't updated and not support jakarta API -->
|
<module>persistence-modules/hibernate-ogm</module> <!-- hibernate-ogm wasn't updated because it doesn't support jakarta API -->
|
||||||
|
<module>persistence-modules/java-cassandra</module> <!-- JAVA-21464 cassandra-unit library doesn't support to run with jdk9 and above -->
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
</profile>
|
</profile>
|
||||||
|
@ -541,8 +542,9 @@
|
||||||
<module>lombok-modules/lombok-custom</module>
|
<module>lombok-modules/lombok-custom</module>
|
||||||
<module>muleesb</module>
|
<module>muleesb</module>
|
||||||
|
|
||||||
<module>persistence-modules/deltaspike</module> <!-- delta spike it doesn't yet the jakarta API-->
|
<module>persistence-modules/deltaspike</module> <!-- delta spike it doesn't support yet the jakarta API-->
|
||||||
<module>persistence-modules/hibernate-ogm</module> <!-- hibernate-ogm wasn't updated and not support jakarta API -->
|
<module>persistence-modules/hibernate-ogm</module> <!-- hibernate-ogm wasn't updated because it doesn't support jakarta API -->
|
||||||
|
<module>persistence-modules/java-cassandra</module> <!-- JAVA-21464 cassandra-unit library doesn't support to run with jdk9 and above -->
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
</profile>
|
</profile>
|
||||||
|
|
Loading…
Reference in New Issue