HHH-4807 only switch CHECK_NULLABILITY's default if Bean Validation is in the class path

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18563 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-01-15 12:57:47 +00:00
parent f93b0441b7
commit 9b38bca8ea
2 changed files with 12 additions and 7 deletions

View File

@ -28,18 +28,12 @@ public class BeanValidationActivator {
public static void activateBeanValidation(EventListeners eventListeners, Properties properties) { public static void activateBeanValidation(EventListeners eventListeners, Properties properties) {
Set<ValidationMode> modes = ValidationMode.getModes( properties.get( MODE_PROPERTY ) ); Set<ValidationMode> modes = ValidationMode.getModes( properties.get( MODE_PROPERTY ) );
if ( modes.contains( ValidationMode.NONE ) ) return;
//de-activate not-null tracking at the core level when Bean Validation is on unless the user really ask for it
if ( properties.getProperty( Environment.CHECK_NULLABILITY ) == null ) {
properties.setProperty( Environment.CHECK_NULLABILITY, "false" );
}
try { try {
//load Validation //load Validation
ReflectHelper.classForName( BV_DISCOVERY_CLASS, BeanValidationActivator.class ); ReflectHelper.classForName( BV_DISCOVERY_CLASS, BeanValidationActivator.class );
} }
catch ( ClassNotFoundException e ) { catch ( ClassNotFoundException e ) {
if ( modes.contains( ValidationMode.CALLBACK ) ) { if ( modes.contains( ValidationMode.CALLBACK ) ) {
throw new HibernateException( "Bean Validation not available in the class path but required in " + MODE_PROPERTY ); throw new HibernateException( "Bean Validation not available in the class path but required in " + MODE_PROPERTY );
} }
@ -48,6 +42,16 @@ public class BeanValidationActivator {
return; return;
} }
} }
//de-activate not-null tracking at the core level when Bean Validation
// is present unless the user really asks for it
//Note that if BV is not present, the behavior is backward compatible
if ( properties.getProperty( Environment.CHECK_NULLABILITY ) == null ) {
properties.setProperty( Environment.CHECK_NULLABILITY, "false" );
}
if ( modes.contains( ValidationMode.NONE ) ) return;
try { try {
Class<?> activator = ReflectHelper.classForName( TYPE_SAFE_ACTIVATOR_CLASS, BeanValidationActivator.class ); Class<?> activator = ReflectHelper.classForName( TYPE_SAFE_ACTIVATOR_CLASS, BeanValidationActivator.class );
Method activateBeanValidation = Method activateBeanValidation =

View File

@ -509,7 +509,8 @@ public final class Environment {
/** /**
* Enable nullability checking. * Enable nullability checking.
* Raises an exception if a property marked as not-null is null. * Raises an exception if a property marked as not-null is null.
* Default to true. * Default to false if Bean Validation is present in the classpath and Hibernate Annotations is used,
* true otherwise.
*/ */
public static final String CHECK_NULLABILITY = "hibernate.check_nullability"; public static final String CHECK_NULLABILITY = "hibernate.check_nullability";