I am working on spring hibernate application and trying to delete from a table using non-id many-to-one relationship based column. Entity classes are:
@Entity
public class Day {
@id(name = "DAY_ID")
dayId;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "DAY_ID")
List<Holiday> holidayList;
...
}
@Entity
public class Holiday {
@id(name="HOLIDAY_ID")
holidayId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "DAY_ID")
Day day;
...
}
I am trying to delete a row from holiday table using hql.
String query = "DELETE FROM Holiday WHERE day.dayId = " + dayObject.getdayId();
Query holidayDeleteQuery = getSession().createQuery(query);
holidayDeleteQuery.executeUpdate();
In the console i am getting proper delete query but on checking DB found out that the row is still there but now the DAY_ID column in holiday table is null. I am not able to figure out why is this happening?
EDIT: help!!! My main problem is why DAY_ID column is changing to null value??