[jboss-user] [EJB 3.0] - Entity bean cascade design issue

alexg79 do-not-reply at jboss.com
Tue Nov 21 09:48:34 EST 2006


I'm sure that a lot of others have run into the same problem as I have.
Suppose you have three entity bean classes: Employee, Customer, Order.
an Order is associated to one Employee and one Customer.
What if an employee who has associated orders gets fired? You can't simply delete his Employee record, because the association from Order prevents it. Orders may not be deleted because you have to keep them all for statistics.
I can think of three ways to handle this:
1. Have the code that removes the Employee nullify the connection to the Employee
2. Use weak references instead (store the ID of the Employee without a foreign key constraint)
3. Use a unidirectional one-to-many association

Problems:
1. Not very scalable, since you have to remember to only remove the entities in question through one specific method, and the method has to know of every single association
2. Can leave dangling IDs behind when the target is removed, and references require explicit queries
3. Ugly, not spec compliant and requires an additional table per association, and association is not visible from the Order object

Is there nothing like "ON DELETE SET NULL" for EJB 3.0 persistence, or Hibernate?
Do I have to resort to native SQL for this?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3987569#3987569

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3987569



More information about the jboss-user mailing list