mirror of
https://github.com/Example-uPagge/hibernate-multiple-bag-fetch-exception.git
synced 2024-06-15 10:55:24 +03:00
update
This commit is contained in:
parent
75b07336e1
commit
14ba09b89f
@ -0,0 +1,58 @@
|
|||||||
|
package dev.struchkov.example.hibernate.nbfe.problem;
|
||||||
|
|
||||||
|
import dev.struchkov.example.hibernate.nbfe.problem.domain.Post;
|
||||||
|
import dev.struchkov.example.hibernate.nbfe.problem.domain.PostComment;
|
||||||
|
import dev.struchkov.example.hibernate.nbfe.problem.domain.Tag;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
|
import jakarta.persistence.Persistence;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
import java.util.stream.LongStream;
|
||||||
|
|
||||||
|
public class GeneratePost {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
final EntityManagerFactory emf = Persistence.createEntityManagerFactory("Blog");
|
||||||
|
final EntityManager entityManager = emf.createEntityManager();
|
||||||
|
|
||||||
|
entityManager.getTransaction().begin();
|
||||||
|
|
||||||
|
for (long j = 0; j < 20; j++) {
|
||||||
|
final Tag tag = new Tag();
|
||||||
|
tag.setId(j);
|
||||||
|
tag.setName("Tag " + j);
|
||||||
|
entityManager.merge(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
entityManager.getTransaction().commit();
|
||||||
|
|
||||||
|
entityManager.getTransaction().begin();
|
||||||
|
|
||||||
|
final List<Tag> tags = entityManager.createQuery("SELECT t FROM Tag t where t.id IN :id", Tag.class)
|
||||||
|
.setParameter("id", LongStream.range(0, 19).boxed().collect(Collectors.toSet()))
|
||||||
|
.getResultList();
|
||||||
|
|
||||||
|
for (int i = 0; i < 50; i++) {
|
||||||
|
final Post post = new Post();
|
||||||
|
post.setTitle("Пост " + i);
|
||||||
|
|
||||||
|
for (int j = 0; j < 1000; j++) {
|
||||||
|
final PostComment postComment = new PostComment();
|
||||||
|
postComment.setReview("Комментарий " + j);
|
||||||
|
post.addComment(postComment);
|
||||||
|
}
|
||||||
|
|
||||||
|
tags.forEach(post::addTag);
|
||||||
|
|
||||||
|
entityManager.merge(post);
|
||||||
|
}
|
||||||
|
|
||||||
|
entityManager.getTransaction().commit();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
package dev.struchkov.example.hibernate.nbfe.problem.domain;
|
package dev.struchkov.example.hibernate.nbfe.problem.domain;
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@ -12,7 +11,6 @@ import lombok.Setter;
|
|||||||
public class Tag {
|
public class Tag {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user