Java Code Examples for org.hibernate.mapping.PersistentClass#getReferencedProperty()

The following examples show how to use org.hibernate.mapping.PersistentClass#getReferencedProperty() . 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: ModelBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void process(InFlightMetadataCollector metadataCollector) {
	log.tracef(
			"Performing delayed property-ref handling [%s, %s, %s]",
			referencedEntityName,
			referencedPropertyName,
			sourceElementSynopsis
	);

	PersistentClass entityBinding = metadataCollector.getEntityBinding( referencedEntityName );
	if ( entityBinding == null ) {
		throw new MappingException(
				String.format(
						Locale.ENGLISH,
						"property-ref [%s] referenced an unmapped entity [%s]",
						sourceElementSynopsis,
						referencedEntityName
				),
				propertyRefOrigin
		);
	}

	Property propertyBinding = entityBinding.getReferencedProperty( referencedPropertyName );
	if ( propertyBinding == null ) {
		throw new MappingException(
				String.format(
						Locale.ENGLISH,
						"property-ref [%s] referenced an unknown entity property [%s#%s]",
						sourceElementSynopsis,
						referencedEntityName,
						referencedPropertyName
				),
				propertyRefOrigin
		);
	}

	if ( isUnique ) {
		( (SimpleValue) propertyBinding.getValue() ).setAlternateUniqueKey( true );
	}
}
 
Example 2
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public org.hibernate.type.Type getReferencedPropertyType(String entityName, String propertyName) throws MappingException {
	final PersistentClass pc = entityBindingMap.get( entityName );
	if ( pc == null ) {
		throw new MappingException( "persistent class not known: " + entityName );
	}
	Property prop = pc.getReferencedProperty( propertyName );
	if ( prop == null ) {
		throw new MappingException(
				"property not known: " +
						entityName + '.' + propertyName
		);
	}
	return prop.getType();
}
 
Example 3
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void process(InFlightMetadataCollector metadataCollector) {
	final PersistentClass clazz = metadataCollector.getEntityBinding( referencedClass );
	if ( clazz == null ) {
		throw new MappingException( "property-ref to unmapped class: " + referencedClass );
	}

	final Property prop = clazz.getReferencedProperty( propertyName );
	if ( unique ) {
		( (SimpleValue) prop.getValue() ).setAlternateUniqueKey( true );
	}
}
 
Example 4
Source File: MetadataImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public org.hibernate.type.Type getReferencedPropertyType(String entityName, String propertyName) throws MappingException {
	final PersistentClass pc = entityBindingMap.get( entityName );
	if ( pc == null ) {
		throw new MappingException( "persistent class not known: " + entityName );
	}
	Property prop = pc.getReferencedProperty( propertyName );
	if ( prop == null ) {
		throw new MappingException(
				"property not known: " +
						entityName + '.' + propertyName
		);
	}
	return prop.getType();
}
 
Example 5
Source File: ModelBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void handlePropertyReference(
		MappingDocument mappingDocument,
		String referencedEntityName,
		String referencedPropertyName,
		boolean isUnique,
		String sourceElementSynopsis) {
	PersistentClass entityBinding = mappingDocument.getMetadataCollector().getEntityBinding( referencedEntityName );
	if ( entityBinding == null ) {
		// entity may just not have been processed yet - set up a delayed handler
		registerDelayedPropertyReferenceHandler(
				new DelayedPropertyReferenceHandlerImpl(
						referencedEntityName,
						referencedPropertyName,
						isUnique,
						sourceElementSynopsis,
						mappingDocument.getOrigin()
				),
				mappingDocument
		);
	}
	else {
		Property propertyBinding = entityBinding.getReferencedProperty( referencedPropertyName );
		if ( propertyBinding == null ) {
			// attribute may just not have been processed yet - set up a delayed handler
			registerDelayedPropertyReferenceHandler(
					new DelayedPropertyReferenceHandlerImpl(
							referencedEntityName,
							referencedPropertyName,
							isUnique,
							sourceElementSynopsis,
							mappingDocument.getOrigin()
					),
					mappingDocument
			);
		}
		else {
			log.tracef(
					"Property [%s.%s] referenced by property-ref [%s] was available - no need for delayed handling",
					referencedEntityName,
					referencedPropertyName,
					sourceElementSynopsis
			);
			if ( isUnique ) {
				( (SimpleValue) propertyBinding.getValue() ).setAlternateUniqueKey( true );
			}
		}
	}
}