Hi all,
opposed to this
http://forum.hibernate.org/viewtopic.php?t=955446
it seems like there is a problem validating beans that have never been attached to the session/EntityManager.
when i do
Code:
ClassValidator cv = new ClassValidator(MyBean.class);
cv.getInvalidValues(aReallyNewAndTransientBeanInstance)
the validator will NOT complain about an invalid bean. (Altough everything works as expected when i try to persist this bean or when i check a detached bean.)
I traced into ClassValidator to see whats happening and i found this code:
Code:
for ( int i = 0; i < memberValidators.size() ; i++ ) {
Member getter = memberGetters.get( i );
if ( Hibernate.isPropertyInitialized(bean, getter.getName() ) ) {
Object value = getMemberValue( bean, getter );
Validator validator = memberValidators.get( i );
if ( !validator.isValid( value ) ) {
String propertyName = getPropertyName( getter );
results.add( new InvalidValue( messages.get( validator ), beanClass, propertyName, value, bean
) );
}
}
}
The thing ist that
Quote:
Hibernate.isPropertyInitialized(...)
returns false for a "new" (transient) bean, and so all my member/property constraints do NOT get checked....
Is this a bug or is there a way to "initialize" a transient bean for use with the validator? ( I tried Hibernate.initalize(...) also, but result was the same...)
My Versions:
* JBoss 4.0.4RC1
* Hibernate Annotations 3.1beta8
* Hibernate EntityManager 3.1beta6
Rgds,
M.