H2 ERROR: Referential integrity constraint violation – Hibernate one to one mapping

Solution for H2 ERROR: Referential integrity constraint violation – Hibernate one to one mapping
is Given Below:

I have two entity (Instructor, InstructorDetail) which have one to one relation.

instructor_detail_id of Instructor entity has a foreign key to the id column of InstructorDetail. So, according to my requirement, when an Instructor is deleted, corresponding instructorDetail also needs to be deleted, but not the vice versa. Now, when I am trying to delete an instructorDetail, it is throwing the referencial integrity constraint error.

Note: I am using H2 db.

Following are the code snippets.

Instructor

import javax.persistence.*;

@Table(name="instructor")
@Entity
public class Instructor implements IdentityMarker<Integer>{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="instructor_id")
    private int id;

    @Column(name="name")
    private String name;

    @Column(name="email")
    private String email;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "instructor_detail_id")//, referencedColumnName = "id")
    private InstructorDetail instructorDetail;


    public Instructor(){

    }
    public Instructor(String name, String email) {
        this.name = name;
        this.email = email;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public InstructorDetail getInstructorDetail() {
        return instructorDetail;
    }

    public void setInstructorDetail(InstructorDetail instructorDetail) {
        this.instructorDetail = instructorDetail;
    }

    public Integer getReference() {
        return id;
    }

    public void setReference(Integer id){ this.id = id;}

    @Override
    public String toString() {
        return "Instructor{" +
                "id=" + id +
                ", name="" + name + "'' +
                ", email="" + email + "'' +
                ", instructorDetail=" + instructorDetail +
                '}';
    }
}

InstructorDetail

import javax.persistence.*;

@Table(name="instructor_detail")
@Entity
public class InstructorDetail implements IdentityMarker<Integer>{

    @Id
    @Column(name="id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name="youtube_link")
    private String youtubeLink;

    @Column(name="hobby")
    private String hobby;

    @OneToOne(cascade = {
                            CascadeType.DETACH,
                            CascadeType.MERGE,
                            CascadeType.PERSIST,
                            CascadeType.REFRESH
                        },
              mappedBy = "instructorDetail")
    // this bi-directional relationship enables us to get the instructor when an instructionDetail is loaded.
    private Instructor instructor;

    public InstructorDetail(){
    }

    public InstructorDetail(String youtubeLink, String hobby){
        this.youtubeLink = youtubeLink;
        this.hobby = hobby;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getYoutubeLink() {
        return youtubeLink;
    }

    public void setYoutubeLink(String youtubeLink) {
        this.youtubeLink = youtubeLink;
    }

    public String getHobby() {
        return hobby;
    }

    public void setHobby(String hobby) {
        this.hobby = hobby;
    }

    public Instructor getInstructor() {
        return instructor;
    }

    public void setInstructor(Instructor instructor) {
        this.instructor = instructor;
    }

    public Integer getReference() {
        return id;
    }

    public void setReference(Integer id){ this.id = id;}

    @Override
    public String toString() {
        return "InstructorDetail{" +
                "id=" + id +
                ", youtubeLink='" + youtubeLink + ''' +
                ", hobby='" + hobby + '''+
                '}';
    }

    @PreRemove
    private void preRemove() {
        System.out.println("pre remove call");
       instructor.setInstructorDetail(null);
    }
}

Following is the client code

private static void deleteInstructorDetail(){
        InstructorDetailDao instructorDetailDao = new InstructorDetailDaoImpl();

        InstructorDetail instructorDetail = instructorDetailDao.getInstructorDetail(2);
        Instructor instructor = instructorDetail.getInstructor();


        System.out.println("Instructor: " + instructor);

        boolean b = instructorDetailDao.deleteInstructorDetail(instructorDetail);

        assert b == true: "InstructorDetail is not deleted!";

        System.out.println("Trying to load Instructor.. It should be deleted!");

        InstructorDao instructorDao = new InstructorDaoImpl();
        instructor = instructorDao.getInstructor(instructor.getId());

        assert instructor != null: "Instructor also got deleted!";

    }

Any help would be appreciated! Thanks in advance.