Hi,
I have 4 tables:
-User
-Admin
-Student
-Secretary
The User table contains everything that is common between Admin, Student and Secretary.
Each of those 3 tables has a FK to an “id” column in User.
I tried something like this:
@Entity
@Table(name = “student”)
public class Student extends User {
@NotNull
@Column(name = "student_identification_number")
private int sin;
//student fields
@Table(name = "user")
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class User<T extends User> {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
@NotNull
int id;
//COMMON FIELDS BETWEEN USER ADMIN AND SECRETARY
The problem is, my FK to the “id” column in User from Student is not existent, and I get
java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`proiect_ip`.`student`, CONSTRAINT `student_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`))
When I try to POST a student.
I tried following this post
Is there another way to do this? I was thinking of creating 3 OneToOne relations in User but that seems weird.