HHH-3898 hibernate.check_nullability (default true)
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@16515 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
b5a1613827
commit
e8dfecb5f7
|
@ -503,6 +503,14 @@ public final class Environment {
|
|||
*/
|
||||
public static final String JACC_CONTEXTID = "hibernate.jacc_context_id";
|
||||
|
||||
/**
|
||||
* Enable nullability checking.
|
||||
* Raises an exception if a property marked as not-null is null.
|
||||
* Default to true.
|
||||
*/
|
||||
public static final String CHECK_NULLABILITY = "hibernate.check_nullability";
|
||||
|
||||
|
||||
public static final String BYTECODE_PROVIDER = "hibernate.bytecode.provider";
|
||||
|
||||
public static final String JPAQL_STRICT_COMPLIANCE= "hibernate.query.jpaql_strict_compliance";
|
||||
|
|
|
@ -95,6 +95,7 @@ public final class Settings {
|
|||
private boolean strictJPAQLCompliance;
|
||||
private boolean namedQueryStartupCheckingEnabled;
|
||||
private EntityTuplizerFactory entityTuplizerFactory;
|
||||
private boolean checkNullability;
|
||||
// private ComponentTuplizerFactory componentTuplizerFactory; todo : HHH-3517 and HHH-1907
|
||||
// private BytecodeProvider bytecodeProvider;
|
||||
|
||||
|
@ -489,7 +490,15 @@ public final class Settings {
|
|||
this.entityTuplizerFactory = entityTuplizerFactory;
|
||||
}
|
||||
|
||||
// void setComponentTuplizerFactory(ComponentTuplizerFactory componentTuplizerFactory) {
|
||||
public boolean isCheckNullability() {
|
||||
return checkNullability;
|
||||
}
|
||||
|
||||
public void setCheckNullability(boolean checkNullability) {
|
||||
this.checkNullability = checkNullability;
|
||||
}
|
||||
|
||||
// void setComponentTuplizerFactory(ComponentTuplizerFactory componentTuplizerFactory) {
|
||||
// this.componentTuplizerFactory = componentTuplizerFactory;
|
||||
// }
|
||||
|
||||
|
|
|
@ -328,6 +328,11 @@ public class SettingsFactory implements Serializable {
|
|||
log.info( "Named query checking : " + enabledDisabled( namedQueryChecking ) );
|
||||
settings.setNamedQueryStartupCheckingEnabled( namedQueryChecking );
|
||||
|
||||
boolean checkNullability = PropertiesHelper.getBoolean(Environment.CHECK_NULLABILITY, properties, true);
|
||||
log.info( "Check Nullability in Core (should be disabled when Bean Validation is on): " + enabledDisabled(useStatistics) );
|
||||
settings.setCheckNullability(checkNullability);
|
||||
|
||||
|
||||
// String provider = properties.getProperty( Environment.BYTECODE_PROVIDER );
|
||||
// log.info( "Bytecode provider name : " + provider );
|
||||
// BytecodeProvider bytecodeProvider = buildBytecodeProvider( provider );
|
||||
|
|
|
@ -42,9 +42,11 @@ import org.hibernate.type.Type;
|
|||
public final class Nullability {
|
||||
|
||||
private final SessionImplementor session;
|
||||
private final boolean checkNullability;
|
||||
|
||||
public Nullability(SessionImplementor session) {
|
||||
this.session = session;
|
||||
this.checkNullability = session.getFactory().getSettings().isCheckNullability();
|
||||
}
|
||||
/**
|
||||
* Check nullability of the class persister properties
|
||||
|
@ -60,7 +62,11 @@ public final class Nullability {
|
|||
final EntityPersister persister,
|
||||
final boolean isUpdate)
|
||||
throws PropertyValueException, HibernateException {
|
||||
|
||||
/*
|
||||
* Typically when Bean Validation is on, we don't want to validate null values
|
||||
* at the Hibernate Core level. Hence the checkNullability setting.
|
||||
*/
|
||||
if ( checkNullability ) {
|
||||
/*
|
||||
* Algorithm
|
||||
* Check for any level one nullability breaks
|
||||
|
@ -116,6 +122,7 @@ public final class Nullability {
|
|||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check sub elements-nullability. Returns property path that break
|
||||
|
|
Loading…
Reference in New Issue