Archive for November, 2006

Hibernate ‘on-delete=cascade’ Performance Tuning

Posted in hibernate, java, performance tuning on November 16, 2006 by eddie

Be careful when you use Hibernate’s support for database ON DELETE CASCADE constraint. If not configured properly, your application might be more performance-costly than you think.

Let me use the example from Gavin King’s email introducing the new setting of on-delete=”cascade”:

<set name="children" inverse="true" cascade="all">
  <key name="PARENT_ID" on-delete="cascade">
  <one -to-many class="Child">
<set>

For a parent object associated with N child objects (cascade=”all”), the setting on-delete=”cascade” avoids issuing N deletes to the database if the parent were to be deleted.

Continue reading

Advertisements

Detecting Infinite Loop

Posted in algorithm, java on November 15, 2006 by eddie

Just yesterday I have come across a problem at work. The problem is the possible occurrence of infinite loop inside a tree structure. To solve it, I need to come up with an algorithm to detect infinite loop occurrence. This little puzzle brings back the memory of a similar and simpler puzzle my high school computer science instructor asked the class.

The problem was: Given an uni-directional linked list, detect infinite loop without using any extra data structure.

Continue reading