tags:

views:

64

answers:

2

When specifying one to many relationships in the domain model....is it better to initialize the set?

i.e.

private Set<Book> books = new HashSet<Book>();

OR

private Set<Book> books;

Thxs.

+3  A: 

Initializing it in the first place prevents you from null checks all over the place, so my advice would be the first.

Willi
is there any disadvantage in initialising?
DD
The cost of a Set which might not be used. Buts it should be worth the price.
Willi
+1  A: 

It doesn't matter from hibernate perspective. It basically question of basic java practice.

fastcodejava