/** * @param value Persistent property. * @return {@code false} if lack of associated entity shall raise an exception, {@code true} otherwise. */ public static boolean ignoreNotFound(Value value) { if ( value instanceof ManyToOne ) { return ( (ManyToOne) value ).isIgnoreNotFound(); } else if ( value instanceof OneToMany ) { return ( (OneToMany) value ).isIgnoreNotFound(); } return false; } }
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { if ( value instanceof ManyToOne ) { ManyToOne manyToOne = (ManyToOne) value; PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() ); if ( ref == null ) { throw new AnnotationException( "@OneToOne or @ManyToOne on " + StringHelper.qualify( entityClassName, path ) + " references an unknown entity: " + manyToOne.getReferencedEntityName() ); } manyToOne.setPropertyName( path ); BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, buildingContext ); TableBinder.bindFk( ref, null, columns, manyToOne, unique, buildingContext ); /* * HbmMetadataSourceProcessorImpl does this only when property-ref != null, but IMO, it makes sense event if it is null */ if ( !manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses ); } else if ( value instanceof OneToOne ) { value.createForeignKey(); } else { throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() ); } } }
public Type getType() throws MappingException { return getMetadata().getTypeResolver().getTypeFactory().manyToOne( getReferencedEntityName(), referenceToPrimaryKey, getReferencedPropertyName(), getPropertyName(), isLazy(), isUnwrapProxy(), isIgnoreNotFound(), isLogicalOneToOne ); }
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { if ( value instanceof ManyToOne ) { ManyToOne manyToOne = (ManyToOne) value; PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() ); if ( ref == null ) { throw new AnnotationException( "@OneToOne or @ManyToOne on " + StringHelper.qualify( entityClassName, path ) + " references an unknown entity: " + manyToOne.getReferencedEntityName() ); } BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, mappings ); TableBinder.bindFk( ref, null, columns, manyToOne, unique, mappings ); /* * HbmBinder does this only when property-ref != null, but IMO, it makes sense event if it is null */ if ( !manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses ); } else if ( value instanceof OneToOne ) { ( (OneToOne) value ).createForeignKey(); } else { throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() ); } } }
/** * @param value Persistent property. * @return {@code false} if lack of associated entity shall raise an exception, {@code true} otherwise. */ public static boolean ignoreNotFound(ValueMapping value) { if ( value instanceof ManyToOne ) { return ( (ManyToOne) value ).isIgnoreNotFound(); } else if ( value instanceof OneToMany ) { return ( (OneToMany) value ).isIgnoreNotFound(); } return false; } }
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 ); }
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { if ( value instanceof ManyToOne ) { ManyToOne manyToOne = (ManyToOne) value; PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() ); if ( ref == null ) { throw new AnnotationException( "@OneToOne or @ManyToOne on " + StringHelper.qualify(entityClassName, path) + " references an unknown entity: " + manyToOne.getReferencedEntityName() ); } BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, mappings ); TableBinder.bindFk( ref, null, columns, manyToOne, unique, mappings ); /* * HbmBinder does this only when property-ref != null, but IMO, it makes sense event if it is null */ if ( ! manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses ); } else if ( value instanceof OneToOne ) { ( (OneToOne) value ).createForeignKey(); } else { throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() ); } } }
public Type getType() throws MappingException { return TypeFactory.manyToOne( getReferencedEntityName(), getReferencedPropertyName(), isLazy(), isEmbedded(), isIgnoreNotFound() ); }
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { if ( value instanceof ManyToOne ) { ManyToOne manyToOne = (ManyToOne) value; PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() ); if ( ref == null ) { throw new AnnotationException( "@OneToOne or @ManyToOne on " + StringHelper.qualify( entityClassName, path ) + " references an unknown entity: " + manyToOne.getReferencedEntityName() ); } BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, mappings ); TableBinder.bindFk( ref, null, columns, manyToOne, unique, mappings ); /* * HbmMetadataSourceProcessorImpl does this only when property-ref != null, but IMO, it makes sense event if it is null */ if ( !manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses ); } else if ( value instanceof OneToOne ) { ( (OneToOne) value ).createForeignKey(); } else { throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() ); } } }
public Type getType() throws MappingException { return TypeFactory.manyToOne( getReferencedEntityName(), getReferencedPropertyName(), isLazy(), isUnwrapProxy(), isEmbedded(), isIgnoreNotFound() ); }
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() ); String cascade = node.attributeValue( "cascade" ); if ( cascade != null && cascade.indexOf( "delete-orphan" ) >= 0 ) { if ( !manyToOne.isLogicalOneToOne() ) { throw new MappingException( "many-to-one attribute [" + path + "] does not support orphan delete as it is not unique" ); } } }
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { if ( value instanceof ManyToOne ) { ManyToOne manyToOne = (ManyToOne) value; PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() ); if ( ref == null ) { throw new AnnotationException( "@OneToOne or @ManyToOne on " + StringHelper.qualify( entityClassName, path ) + " references an unknown entity: " + manyToOne.getReferencedEntityName() ); } BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, mappings ); TableBinder.bindFk( ref, null, columns, manyToOne, unique, mappings ); /* * HbmMetadataSourceProcessorImpl does this only when property-ref != null, but IMO, it makes sense event if it is null */ if ( !manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses ); } else if ( value instanceof OneToOne ) { ( (OneToOne) value ).createForeignKey(); } else { throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() ); } } }
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() ); String cascade = node.attributeValue( "cascade" ); if ( cascade != null && cascade.indexOf( "delete-orphan" ) >= 0 ) { if ( !manyToOne.isLogicalOneToOne() ) { throw new MappingException( "many-to-one attribute [" + path + "] does not support orphan delete as it is not unique" ); } } }
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { if ( value instanceof ManyToOne ) { final ManyToOne manyToOne = (ManyToOne) value; final PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() ); if ( ref == null ) { throw new AnnotationException( "@OneToOne or @ManyToOne on " + StringHelper.qualify( entityClassName, path ) + " references an unknown entity: " + manyToOne.getReferencedEntityName() ); } manyToOne.setPropertyName( path ); BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, buildingContext ); TableBinder.bindFk( ref, null, columns, manyToOne, unique, buildingContext ); /* * HbmMetadataSourceProcessorImpl does this only when property-ref != null, but IMO, it makes sense event if it is null */ if ( !manyToOne.isIgnoreNotFound() ) { manyToOne.createPropertyRefConstraints( buildingContext ); } } else if ( value instanceof OneToOne ) { value.createForeignKey(); } else { throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() ); } } }
public Type getType() throws MappingException { return getMappings().getTypeResolver().getTypeFactory().manyToOne( getReferencedEntityName(), getReferencedPropertyName(), isLazy(), isUnwrapProxy(), isEmbedded(), isIgnoreNotFound(), isLogicalOneToOne ); }
public Type getType() throws MappingException { return getMappings().getTypeResolver().getTypeFactory().manyToOne( getReferencedEntityName(), getReferencedPropertyName(), isLazy(), isUnwrapProxy(), isEmbedded(), isIgnoreNotFound(), isLogicalOneToOne ); }
: PersistentAttributeType.MANY_TO_ONE; constrained = true; notFoundAction = manyToOne.isIgnoreNotFound() ? NotFoundAction.IGNORE : NotFoundAction.EXCEPTION;