package ru.mcs.diary.student;
import jakarta.persistence.*;
import lombok.*;
import ru.mcs.diary.parent.Parent;
import ru.mcs.diary.parent.ParentType;
import java.time.LocalDateTime;
@Entity
@Table(name = "student_parents", uniqueConstraints = {
@UniqueConstraint(columnNames = {"student_id", "parent_type"})
})
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class StudentParent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "student_id", nullable = false)
private Student student;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id", nullable = false)
private Parent parent;
@Enumerated(EnumType.STRING)
@Column(name = "parent_type", nullable = false, length = 20)
private ParentType parentType;
@Column(name = "created_at", nullable = false, updatable = false)
@Builder.Default
private LocalDateTime createdAt = LocalDateTime.now();
}