Take the 2-minute tour ×

I have such structure:

// all objects have valid mapping to database
public class Child {
   private int id;
   private String name;
public class Parent {
   private int id;
   private String name;
   private List<Child> chidlren;

and I have to update specific child B inside parent A.

There are two ways:

  1. Update child's fields inside collection and update the whole object:
    Parent temp = dao.getParent(id);

  2. Update only child object:
    Child temp = dao.getChild(id);

Which one is better if I want to get more perfomance?

Thank you

share|improve this question
Have you tried to analyse? I would think they would be pretty much the same because hibernate does a lot if optimizing –  RNJ Sep 7 '12 at 17:48
My opinion is that the second solution will be faster even with hibernate optimization. If you haven't any additional queries of course. I just wanted to hear another thoughts –  nKognito Sep 7 '12 at 18:26

1 Answer 1

up vote 1 down vote accepted

On the surface, I would surmise that the second solution

2.Update only child object

would be more performant.

However, the only way you determine this quantitatively would be to turn on Hibernate's show_sql, capture the SQL for Solution 1 and Solution 2, run an Explain Plan for each of your solutions, and compare the resulting Explain Plans.

You could get differing results depending on what else has changed/not changed in the Parent object and other children in the Parent.children collection. When capturing SQL for Explain Plans, you would want to try different scenarios.

share|improve this answer

Your Answer


