Friday, February 25, 2011

javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: bla

org.hibernate.PropertyValueException is a nice animal, containing a lot of useful info:

entityName
propertyName

so instead of doing yourself the validation on all the properties to be persisted, you can delegate Hibernate.

The problem with Hibernate is that it's a fail-fast validation: the first invalid property (null or referencing an non existing entity) will throw an exception.

If you want to capture ALL the validation errors, then you need to do it individually testing each property.

No comments: