Java Code Examples for org.hibernate.type.CompositeType#getPropertyNullability()

The following examples show how to use org.hibernate.type.CompositeType#getPropertyNullability() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Nullability.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * check component nullability. Returns property path that break
 * nullability or null if none
 *
 * @param value component properties
 * @param compositeType component not-nullable type
 *
 * @return property path
 * @throws HibernateException error while getting subcomponent values
 */
private String checkComponentNullability(Object value, CompositeType compositeType) throws HibernateException {
	// IMPL NOTE : we currently skip checking "any" and "many to any" mappings.
	//
	// This is not the best solution.  But atm there is a mismatch between AnyType#getPropertyNullability
	// and the fact that cascaded-saves for "many to any" mappings are not performed until after this nullability
	// check.  So the nullability check fails for transient entity elements with generated identifiers because
	// the identifier is not yet generated/assigned (is null)
	//
	// The more correct fix would be to cascade saves of the many-to-any elements before the Nullability checking

	if ( compositeType.isAnyType() ) {
		return null;
	}

	final boolean[] nullability = compositeType.getPropertyNullability();
	if ( nullability != null ) {
		//do the test
		final Object[] subValues = compositeType.getPropertyValues( value, session );
		final Type[] propertyTypes = compositeType.getSubtypes();
		for ( int i = 0; i < subValues.length; i++ ) {
			final Object subValue = subValues[i];
			if ( !nullability[i] && subValue==null ) {
				return compositeType.getPropertyNames()[i];
			}
			else if ( subValue != null ) {
				final String breakProperties = checkSubElementsNullability( propertyTypes[i], subValue );
				if ( breakProperties != null ) {
					return buildPropertyPath( compositeType.getPropertyNames()[i], breakProperties );
				}
			}
		}
	}
	return null;
}
 
Example 2
Source File: ForeignKeys.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static void collectNonNullableTransientEntities(
		Nullifier nullifier,
		Object value,
		String propertyName,
		Type type,
		boolean isNullable,
		SharedSessionContractImplementor session,
		NonNullableTransientDependencies nonNullableTransientEntities) {
	if ( value == null ) {
		return;
	}

	if ( type.isEntityType() ) {
		final EntityType entityType = (EntityType) type;
		if ( !isNullable
				&& !entityType.isOneToOne()
				&& nullifier.isNullifiable( entityType.getAssociatedEntityName(), value ) ) {
			nonNullableTransientEntities.add( propertyName, value );
		}
	}
	else if ( type.isAnyType() ) {
		if ( !isNullable && nullifier.isNullifiable( null, value ) ) {
			nonNullableTransientEntities.add( propertyName, value );
		}
	}
	else if ( type.isComponentType() ) {
		final CompositeType actype = (CompositeType) type;
		final boolean[] subValueNullability = actype.getPropertyNullability();
		if ( subValueNullability != null ) {
			final String[] subPropertyNames = actype.getPropertyNames();
			final Object[] subvalues = actype.getPropertyValues( value, session );
			final Type[] subtypes = actype.getSubtypes();
			for ( int j = 0; j < subvalues.length; j++ ) {
				collectNonNullableTransientEntities(
						nullifier,
						subvalues[j],
						subPropertyNames[j],
						subtypes[j],
						subValueNullability[j],
						session,
						nonNullableTransientEntities
				);
			}
		}
	}
}