Чуток тесты не проходят

This commit is contained in:
ArtemEmelyanov 2023-04-15 17:40:26 +04:00
parent 3ecb50cec8
commit 71a1250ae1
8 changed files with 5749 additions and 12 deletions

Binary file not shown.

5737
data.trace.db Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,8 @@
package ru.IP_LabWorks.IP.University.Model;
import jakarta.persistence.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import java.util.ArrayList;
import java.util.List;
@ -13,10 +15,11 @@ public class Group {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@OneToMany(fetch = FetchType.EAGER)
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Student> students;
@ManyToMany
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Subject> subjects;
public Group() {

View File

@ -1,6 +1,8 @@
package ru.IP_LabWorks.IP.University.Model;
import jakarta.persistence.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import java.util.List;
import java.util.Objects;
@ -12,7 +14,8 @@ public class Subject {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@ManyToMany(fetch = FetchType.EAGER)
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@OnDelete(action = OnDeleteAction.CASCADE)
private List<Group> groups;
public Subject() {

View File

@ -8,7 +8,6 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import ru.IP_LabWorks.IP.University.Model.Group;
import ru.IP_LabWorks.IP.University.Model.Student;
import ru.IP_LabWorks.IP.University.Model.Subject;
import java.util.List;

View File

@ -7,7 +7,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import ru.IP_LabWorks.IP.University.Model.Student;
import ru.IP_LabWorks.IP.University.Model.Subject;
import java.util.List;

View File

@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import ru.IP_LabWorks.IP.University.Model.Group;
import ru.IP_LabWorks.IP.University.Model.Student;
import ru.IP_LabWorks.IP.University.Model.Subject;
import java.util.List;
@ -17,9 +18,6 @@ public class SubjectService {
@PersistenceContext
private EntityManager em;
@Autowired
private GroupService groupService;
@Transactional
public Subject addSubject(String name){
if (!StringUtils.hasText(name)) {
@ -69,7 +67,7 @@ public class SubjectService {
@Transactional
public void addGroupToSubject(Long subjectId, Long groupId) {
Subject subject = findSubject(subjectId);
Group group = groupService.findGroup(groupId);
Group group = em.find(Group.class, groupId);
subject.getGroups().add(group);
group.getSubjects().add(subject);
em.merge(subject);
@ -79,7 +77,7 @@ public class SubjectService {
@Transactional
public void removeGroupFromSubject(Long subjectId, Long groupId) {
Subject subject = findSubject(subjectId);
Group group = groupService.findGroup(groupId);
Group group = em.find(Group.class, groupId);
subject.getGroups().remove(group);
group.getSubjects().remove(subject);
em.merge(subject);

View File

@ -6,9 +6,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import ru.IP_LabWorks.IP.University.Model.Student;
import ru.IP_LabWorks.IP.University.Model.Subject;
import ru.IP_LabWorks.IP.University.Service.StudentService;
import ru.IP_LabWorks.IP.University.Service.SubjectService;
import java.util.List;