diff --git a/src/main/java/dev/struchkov/example/hibernate/nbfe/problem/ProblemMain.java b/src/main/java/dev/struchkov/example/hibernate/nbfe/no_fix_set/NoFixSetMain.java similarity index 72% rename from src/main/java/dev/struchkov/example/hibernate/nbfe/problem/ProblemMain.java rename to src/main/java/dev/struchkov/example/hibernate/nbfe/no_fix_set/NoFixSetMain.java index 5964c05..ac230b4 100644 --- a/src/main/java/dev/struchkov/example/hibernate/nbfe/problem/ProblemMain.java +++ b/src/main/java/dev/struchkov/example/hibernate/nbfe/no_fix_set/NoFixSetMain.java @@ -1,18 +1,19 @@ -package dev.struchkov.example.hibernate.nbfe.problem; +package dev.struchkov.example.hibernate.nbfe.no_fix_set; -import dev.struchkov.example.hibernate.nbfe.problem.domain.Post; +import dev.struchkov.example.hibernate.nbfe.no_fix_set.domain.Post; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Persistence; import java.util.List; -public class ProblemMain { +public class NoFixSetMain { public static void main(String[] args) { final EntityManagerFactory emf = Persistence.createEntityManagerFactory("Blog"); final EntityManager entityManager = emf.createEntityManager(); + final long startTime = System.currentTimeMillis(); final List posts = entityManager.createQuery( """ SELECT p @@ -25,7 +26,9 @@ public class ProblemMain { .setParameter("minId", 1L) .setParameter("maxId", 50L) .getResultList(); + + final long finishTime = System.currentTimeMillis(); + System.out.println("Performance: " + (startTime - finishTime)); } - } diff --git a/src/main/java/dev/struchkov/example/hibernate/nbfe/problem/domain/Post.java b/src/main/java/dev/struchkov/example/hibernate/nbfe/no_fix_set/domain/Post.java similarity index 83% rename from src/main/java/dev/struchkov/example/hibernate/nbfe/problem/domain/Post.java rename to src/main/java/dev/struchkov/example/hibernate/nbfe/no_fix_set/domain/Post.java index 761ba30..eeddac6 100644 --- a/src/main/java/dev/struchkov/example/hibernate/nbfe/problem/domain/Post.java +++ b/src/main/java/dev/struchkov/example/hibernate/nbfe/no_fix_set/domain/Post.java @@ -1,4 +1,4 @@ -package dev.struchkov.example.hibernate.nbfe.problem.domain; +package dev.struchkov.example.hibernate.nbfe.no_fix_set.domain; import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; @@ -11,8 +11,8 @@ import jakarta.persistence.OneToMany; import lombok.Getter; import lombok.Setter; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; @Entity @Getter @@ -30,7 +30,7 @@ public class Post { cascade = CascadeType.ALL, orphanRemoval = true ) - private List comments = new ArrayList<>(); + private Set comments = new HashSet<>(); @ManyToMany( cascade = { @@ -43,7 +43,7 @@ public class Post { joinColumns = @JoinColumn(name = "post_id"), inverseJoinColumns = @JoinColumn(name = "tag_id") ) - private List tags = new ArrayList<>(); + private Set tags = new HashSet<>(); public void addComment(PostComment postComment) { postComment.setPost(this); diff --git a/src/main/java/dev/struchkov/example/hibernate/nbfe/problem/domain/PostComment.java b/src/main/java/dev/struchkov/example/hibernate/nbfe/no_fix_set/domain/PostComment.java similarity index 85% rename from src/main/java/dev/struchkov/example/hibernate/nbfe/problem/domain/PostComment.java rename to src/main/java/dev/struchkov/example/hibernate/nbfe/no_fix_set/domain/PostComment.java index 5e67aca..d875459 100644 --- a/src/main/java/dev/struchkov/example/hibernate/nbfe/problem/domain/PostComment.java +++ b/src/main/java/dev/struchkov/example/hibernate/nbfe/no_fix_set/domain/PostComment.java @@ -1,4 +1,4 @@ -package dev.struchkov.example.hibernate.nbfe.problem.domain; +package dev.struchkov.example.hibernate.nbfe.no_fix_set.domain; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; diff --git a/src/main/java/dev/struchkov/example/hibernate/nbfe/problem/domain/Tag.java b/src/main/java/dev/struchkov/example/hibernate/nbfe/no_fix_set/domain/Tag.java similarity index 81% rename from src/main/java/dev/struchkov/example/hibernate/nbfe/problem/domain/Tag.java rename to src/main/java/dev/struchkov/example/hibernate/nbfe/no_fix_set/domain/Tag.java index b321125..9f8555b 100644 --- a/src/main/java/dev/struchkov/example/hibernate/nbfe/problem/domain/Tag.java +++ b/src/main/java/dev/struchkov/example/hibernate/nbfe/no_fix_set/domain/Tag.java @@ -1,4 +1,4 @@ -package dev.struchkov.example.hibernate.nbfe.problem.domain; +package dev.struchkov.example.hibernate.nbfe.no_fix_set.domain; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index dd2d39d..70b42b9 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -4,9 +4,9 @@ http://xmlns.jcp.org/xml/ns/persistence_2_1.xsd"> - dev.struchkov.example.hibernate.nbfe.problem.domain.Post - dev.struchkov.example.hibernate.nbfe.problem.domain.PostComment - dev.struchkov.example.hibernate.nbfe.problem.domain.Tag + dev.struchkov.example.hibernate.nbfe.no_fix_set.domain.Post + dev.struchkov.example.hibernate.nbfe.no_fix_set.domain.PostComment + dev.struchkov.example.hibernate.nbfe.no_fix_set.domain.Tag true