I am working on a basic example to test cascade delete
operation but I am getting exception.
I have below entities:
Employee.java
When you delete Employee on session try to add this, I had the same issue:
session.delete(session.get(Employee.class, employee_Id));
On my issue I had Movie and TimeTable relation was OneToOne:
On Movie model:
public class Movie implements Serializable
{
@Id
@Column(name = "fid")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int fid;
....
@OneToOne(mappedBy = "movie", cascade = CascadeType.ALL, orphanRemoval = true)
private TimeTable timetable;
}
On TimeTable model:
public class TimeTable implements Serializable
{
...
@OneToOne
@JoinColumn(name = "fid")
private Movie movie;
}
The REMOVE cascade type is for the standard JPA remove()
operation. For the native Hibernate delete()
operation, you need to use a Hibernate-proprietary annotation:
@Cascade(CascadeType.DELETE)