I have a question about the validity of using cascading delete Hibernate definitions.
My example involves two entities 'Customer' and 'Order'. My Hibernate design envisages these as being two discrete hibernate mappings. Although a customer is associated with an order (the order table will include a 'customer ID' foreign key column), the orders are not defined at the same or place as customers are created and maintained.
Hence...
Code:
public class Customer {
private int CustomerID;
private String CustomerName;
...
...
}
public class Order {
private int OrderID;
private String OrderNumber;
private double OrderAmount;
private int CustomerID;
...
...
}
As the Customer class is potentially quite large neither does it make sense for the customer class to be added as a property to the Order class.
Thus, I have two separate Hibernate mappings for one each class, with no one-to-many association included in the Customer mapping.
The downside of this approach is that I lose the cascading delete facility by having the association between customer and order.
To address this is it valid to create a second class that descends from 'Customer' with its own Hibernate mapping that overlays the same customer table. THis new mapping would be used solely as a vehicle for delete operations?
Like..
Code:
public class CustomerPlus extends Customer {
private Set<Order> fOrders = new HashSet<Order>()
...
...
}
In the Hibernate mapping for 'CustomerPlus' I'd add a lazy load one to many association with a cascading delete. For all customer 'delete' operations in the DAO tier Java class I'd load the CustomerPlus class and use it as a vehicle to enact deletion of the related orders.
Does this make sense? Thoughts?