Для данила

This commit is contained in:
ArtemEmelyanov 2023-03-26 12:53:15 +04:00
parent 4b71c89826
commit 4f9bba63ee
4 changed files with 66 additions and 0 deletions

BIN
data.mv.db Normal file

Binary file not shown.

View File

@ -2,6 +2,9 @@ package ru.IP_LabWorks.IP.University.Model;
import jakarta.persistence.*;
import java.util.List;
import java.util.Objects;
@Entity
@Table(name = "groups")
public class Group {
@ -9,4 +12,34 @@ public class Group {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@OneToMany
@JoinTable(name = "students_in_groups",
joinColumns = @JoinColumn(name = "group_id"),
inverseJoinColumns = @JoinColumn(name = "student_id"))
private List<Student> students;
public Long getId() { return id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Group group = (Group) o;
return Objects.equals(id, group.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Group{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}

View File

@ -18,6 +18,9 @@ public class Student {
inverseJoinColumns = @JoinColumn(name = "subject_id"))
private List<Subject> subjects;
public Student() {
}
public Student(String name, Integer age) {
this.name = name;
this.age = age;
@ -36,4 +39,18 @@ public class Student {
Student student = (Student) o;
return Objects.equals(id, student.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Student{" +
"id=" + id +
", name='" + name + '\'' +
", age='" + age + '\'' +
'}';
}
}

View File

@ -15,6 +15,9 @@ public class Subject {
@ManyToMany(mappedBy = "subjects")
private List<Student> students;
public Subject() {
}
public Subject(String name) {
this.name = name;
}
@ -30,4 +33,17 @@ public class Subject {
Subject subject = (Subject) o;
return Objects.equals(id, subject.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public String toString() {
return "Subject{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}