My team made a decision not to remove entries from database, but to give them a status like ACTIVE
or DELETED
.
Problem arises when, for entity - let's call it Customer
I make a collection of another entities:
@Entity
public class Customer {
@ManyToMany
private List<Order> orders;
private MyEnumStatus status;
...
}
If I want to 'remove' one order from the list orders
I have no influence on how is it done (especially - it will certainly not set desired status on entry in the link table and instead it will just remove a record from it).
@PersistenceContext
EntityManager em;
...
Customer customer = customerService.getRandomOne();
customer.getOrders().remove(0);
em.merge(customer);
My question is - is it possible to apply a status field (in Order entity) to this scenario? I mean to somehow overwrite this behaviour to set statuses instead of removing entries.