EclipseLink Remove Cascade

529 views Asked by At

I have been developing a web application running on the Glassfish Server. I use JPA with EclipseLink implementation.

These are my two entity classes. I represent the relation between them below. When I start the Glassfish server and delete the lesson entity, Cascade works. It deletes all of the Test entities of it. Then I add lesson entity and test entity related to it. But when I try to delete the Lesson entity, at this time Cascade does not work and throws "foreign key constraint" error. After Server restarting, Cascade again works. ??? What is the difference? Why do Cascade operation only work at the startup?

Thank you.

@Entity
public class Lesson implements Serializable {

    ...

 @OneToMany( fetch = FetchType.LAZY, cascade = { CascadeType.MERGE, CascadeType.REMOVE }, mappedBy = "lesson" )
private List< Test >        tests;

    ...
}

@Entity
public class Test implements Serializable {

   ...

   @ManyToOne( targetEntity = Lesson.class, fetch = FetchType.LAZY )
   @JoinColumn( name = "lessonNo", insertable = true, updatable = true, nullable = false )
   private Lesson               lesson;

   ...
}
0

There are 0 answers