Say I have the following Hibernate-mapped class:
public class ClassA {
@OneToMany(fetch=EAGER)
private List<ClassB> bList;
}
When I read an object of ClassA
from a Hibernate session, the bList
field is initialized with a PersistentList
object, as expected.
I find myself with a requirement where in situations where the list is empty, I need Hibernate to initialize the bList
field to null
, rather than with an empty PersistentList
. In theory, Hibernate has the information it needs to do this, since the fetch on the list is eager. The problem is that according to section 6.1 of the Hibernate docs:
Due to the underlying relational model, collection-valued properties do not support null value semantics. Hibernate does not distinguish between a null collection reference and an empty collection.
This makes perfect sense, but I'm hoping someone can come up with a cunning ruse to overcome this limitation. I'm thinking perhaps some listener/callback mechanism might allow me to replace empty lists with null references.