Hibernate needs the collection reference in order to track additions to the collection. If your application requires empty collections to be presented as null, your best bet would be to configure the mapping such that Hibernate directly accesses the fields; then your applications can access through the property getter which does:
Code:
public Set getMyCollection() {
if (myCollection.isEmpty()) {
return null;
}
else {
return myCollection;
}
}
You can also modify the setter to "swap" the empty collection with null, but that will cause Hibernate to attempt to delete the collection during flush. I'd, obviously, not recommend this approach ;)