users@glassfish.java.net

Design question on JPA and cleaning up relationships

From: <glassfish_at_javadesktop.org>
Date: Tue, 09 Sep 2008 15:53:07 PDT

I have the following situation. I have an Alarm entity that references a Device entity that the alarm is associated with. I currently have a @ManyToOne uni-directional relationship from the Alarm to the Device (the Alarm knows the associated device but the device does not directly know the alarms associated with it). When a Device entity is removed, I want to remove all of the Alarm entities that are referencing it. There could be many thousand Alarm entites associated with a Device, so I am concerned on performance, memory utilization, etc. I have a feeling if I do this in one big transaction I could run out of resources.

One thought is to perform a bulk delete of the Alarm entities in a transaction but I also have an EntityListener on the Alarm entity and am concerned that the listener would be invoked on each AlarmEvent being deleted and what performance impact that would be.

So any thoughts on how to remove many thousand associated entities in an efficient manner will be greatly appreciated.

Brett
[Message sent by forum member 'bbergquist' (bbergquist)]

http://forums.java.net/jive/thread.jspa?messageID=298182