Hi All,
I am using Hibernate 3.2.1 with Java5 annotations and MySQL as database.
In my domain model I have an entity "ApprovalRequest" which has a unidirectional ManyToOne association to an entity "Image".
Code:
public class ApprovalRequest
{
@ManyToOne
private Image image;
...
}
public class Image
{
...
}
Per default hibernate seems to map this association as foreign key relation resulting in an "image_id" column in my "approvalrequest" table which is perfectly fine. Additionally a foreign key constraint is added to the "image_id" column.
My problem is that I have to delete Image entities which results in org.hibernate.exception.ConstraintViolationException because of the foreign key constraint on the "image_id" column.
Is it possible to instruct hibernate to reset the value of the "image_id" column to null if an "Image" entity is deleted or do I have to handle this in my code?