views:

43

answers:

1

Taken from here: http://docs.jboss.org/hibernate/stable/core/reference/en/html/persistent-classes.html#persistent-classes-equalshashcode

I tend to use List since Criteria returns List, so it makes my code cleaner since I don't have to do conversion.

I do something like so..

@OneToMany(cascade= {CascadeType.PERSIST, CascadeType.REMOVE}, mappedBy="parent")
@Column(name="PARENT_ID")
public List<Menu> getChildMenus() {
    return childMenus;
}

If I had use Set there, somewhere in my DAO I will have to convert results returned by Criteria to Set first.

I wonder what the repercussion could be by using List they way I am doing.

+5  A: 

Set is used as the child table has a primary key such that a child can only be once in a parent. If you use a list there can be duplicate children in the list and this cannot be saved to the database.

Mark