Java Code Examples for org.hibernate.mapping.ManyToOne#setForeignKeyName()

The following examples show how to use org.hibernate.mapping.ManyToOne#setForeignKeyName() . 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: HbmBinder.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void bindManyToOne(Element node, ManyToOne manyToOne, String path,
		boolean isNullable, Mappings mappings) throws MappingException {

	bindColumnsOrFormula( node, manyToOne, path, isNullable, mappings );
	initOuterJoinFetchSetting( node, manyToOne );
	initLaziness( node, manyToOne, mappings, true );

	Attribute ukName = node.attribute( "property-ref" );
	if ( ukName != null ) {
		manyToOne.setReferencedPropertyName( ukName.getValue() );
	}

	manyToOne.setReferencedEntityName( getEntityName( node, mappings ) );

	String embed = node.attributeValue( "embed-xml" );
	manyToOne.setEmbedded( embed == null || "true".equals( embed ) );

	String notFound = node.attributeValue( "not-found" );
	manyToOne.setIgnoreNotFound( "ignore".equals( notFound ) );

	if( ukName != null && !manyToOne.isIgnoreNotFound() ) {
		if ( !node.getName().equals("many-to-many") ) { //TODO: really bad, evil hack to fix!!!
			mappings.addSecondPass( new ManyToOneSecondPass(manyToOne) );
		}
	}

	Attribute fkNode = node.attribute( "foreign-key" );
	if ( fkNode != null ) manyToOne.setForeignKeyName( fkNode.getValue() );

	validateCascade( node, path );
}
 
Example 2
Source File: ModelBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void bindManyToOneAttribute(
		final MappingDocument sourceDocument,
		final SingularAttributeSourceManyToOne manyToOneSource,
		ManyToOne manyToOneBinding,
		String referencedEntityName) {
	// NOTE : no type information to bind

	manyToOneBinding.setReferencedEntityName( referencedEntityName );
	if ( StringHelper.isNotEmpty( manyToOneSource.getReferencedEntityAttributeName() ) ) {
		manyToOneBinding.setReferencedPropertyName( manyToOneSource.getReferencedEntityAttributeName() );
		manyToOneBinding.setReferenceToPrimaryKey( false );
	}
	else {
		manyToOneBinding.setReferenceToPrimaryKey( true );
	}

	manyToOneBinding.setLazy( manyToOneSource.getFetchCharacteristics().getFetchTiming() == FetchTiming.DELAYED );
	manyToOneBinding.setUnwrapProxy( manyToOneSource.getFetchCharacteristics().isUnwrapProxies() );
	manyToOneBinding.setFetchMode(
			manyToOneSource.getFetchCharacteristics().getFetchStyle() == FetchStyle.SELECT
					? FetchMode.SELECT
					: FetchMode.JOIN
	);

	if ( manyToOneSource.isEmbedXml() == Boolean.TRUE ) {
		DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfEmbedXmlSupport();
	}

	manyToOneBinding.setIgnoreNotFound( manyToOneSource.isIgnoreNotFound() );

	if ( StringHelper.isNotEmpty( manyToOneSource.getExplicitForeignKeyName() ) ) {
		manyToOneBinding.setForeignKeyName( manyToOneSource.getExplicitForeignKeyName() );
	}

	final ManyToOneColumnBinder columnBinder = new ManyToOneColumnBinder(
			sourceDocument,
			manyToOneSource,
			manyToOneBinding,
			referencedEntityName
	);
	final boolean canBindColumnsImmediately = columnBinder.canProcessImmediately();
	if ( canBindColumnsImmediately ) {
		columnBinder.doSecondPass( null );
	}
	else {
		sourceDocument.getMetadataCollector().addSecondPass( columnBinder );
	}

	if ( !manyToOneSource.isIgnoreNotFound() ) {
		// we skip creating the FK here since this setting tells us there
		// cannot be a suitable/proper FK
		final ManyToOneFkSecondPass fkSecondPass = new ManyToOneFkSecondPass(
				sourceDocument,
				manyToOneSource,
				manyToOneBinding,
				referencedEntityName
		);

		if ( canBindColumnsImmediately && fkSecondPass.canProcessImmediately() ) {
			fkSecondPass.doSecondPass( null );
		}
		else {
			sourceDocument.getMetadataCollector().addSecondPass( fkSecondPass );
		}
	}

	manyToOneBinding.setCascadeDeleteEnabled( manyToOneSource.isCascadeDeleteEnabled() );
}