[hibernate-dev] HV: Considering static vs. runtime type for property path creation

Gunnar Morling gunnar.morling at googlemail.com
Wed Apr 20 18:11:09 EDT 2011


Hi guys,

there was an interesting question on the Validator forum
(https://forum.hibernate.org/viewtopic.php?f=9&t=1010626&start=0)
which IMO boils down to the question whether the static or the runtime
type of an association should be considered when creating property
paths in case of cascading validations.

An example:

class Foo {

    private Collection<Bar> bar1 = new ArrayList<Bar>();

    private List<Bar> bar2 = new ArrayList<Bar>();

}

When validating an instance of Foo (which has invalid elements in
bar1/bar2) with HV, the resulting property path node for bar1 would be
iterable but not indexable ("bar1[]"), while the property path node
for bar2 would be iterable and indexable ("bar2[123]"). This is that
way because the static type of bar1/bar2 (Collection vs. List) is
considered when building the nodes, and not the runtime type
(ArrayList in both cases).

That said, basing the path on the runtime type instead would seem
reasonable to me, too (as for instance the constraints to validate are
also determined based on the runtime type of references). I scanned
through the BV spec. (section 4.5) but didn't find a clear answer
which approach should be followed. Are there any opinions on that?

Thanks,

Gunnar



More information about the hibernate-dev mailing list