In my Hibernate classes should instance collections be initialized
public class Basket {
private List items = new ArrayList();
...getters and setters...
}
or left uninitalized
public class Basket {
private List items;
...getters and setters...
}
does it make any kind of difference for Hibernate? I came across this Hibernate documentation where it initializes their HashSet, but I have often seen them left uninitialized.
From Hibernate’s
persistent collectiondocumentation:And …
These “non-null collection” and “persistent” versus “non-persistent” semantics sometimes gets lost with developers. To keep things simple with Hibernate objects, I prefer:
Collectionswithjava.utilimplementationsCollectioninterfacesMaking it customary for Hibernate object
Collections never being NULL and avoiding the pitfall noted in the above documentation of casting a Hibernate objectCollectionto an invalid implementation.