I have here a very big and complex legacy datamodell on which i mapped entities with hbm 3.5.
ProblemThe speciell on this datamodel you shouldn't delete entries in the database you just update a validToDate value.Code:
@Entity
class Address{
int id;
List children;
Date validTo;
}
Code:
session.delete(address) - should do > UPDATE address SET validTo=current_date() WHERE id =1
every table has this column. Advantage: the change of values is transparent.
Possible solutions I thought:
- with a DAO you can write DAO.delete(address) and make internally a update.
The Problem are the children, which should be deleted over @Cascade(value = CascadeType.DELETE_ORPHAN).
I could relinquish this, but than I need a easy transparent solution (the datamodel is very big and complex - i generated it over hbm generator)
- Hibernate Interceptors could catch the delete, but can not change it into update
- On DB level (Postgres) I could use on delete trigger, but sometimes I need a real delete
Also the retrieve of the data with WHERE validToDate>=currentDate() i want to solve transparent
Perhaps somebody knows this problem or has a idea. thx