private void makeOneToManyMapKeyColumnNullableIfNotInProperty( final XProperty property) { final org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection; if ( map.isOneToMany() && property.isAnnotationPresent( MapKeyColumn.class ) ) { final Value indexValue = map.getIndex(); if ( indexValue.getColumnSpan() != 1 ) { throw new AssertionFailure( "Map key mapped by @MapKeyColumn does not have 1 column" ); } final Selectable selectable = indexValue.getColumnIterator().next(); if ( selectable.isFormula() ) { throw new AssertionFailure( "Map key mapped by @MapKeyColumn is a Formula" ); } Column column = (Column) map.getIndex().getColumnIterator().next(); if ( !column.isNullable() ) { final PersistentClass persistentClass = ( ( OneToMany ) map.getElement() ).getAssociatedClass(); // check if the index column has been mapped by the associated entity to a property; // @MapKeyColumn only maps a column to the primary table for the one-to-many, so we only // need to check "un-joined" properties. if ( !propertyIteratorContainsColumn( persistentClass.getUnjoinedPropertyIterator(), column ) ) { // The index column is not mapped to an associated entity property so we can // safely make the index column nullable. column.setNullable( true ); } } } }
@Override protected void createBackReferences() { super.createBackReferences(); boolean indexIsFormula = false; Iterator itr = getCollectionBinding().getIndex().getColumnIterator(); while ( itr.hasNext() ) { if ( ( (Selectable) itr.next() ).isFormula() ) { indexIsFormula = true; } } if ( getCollectionBinding().isOneToMany() && !getCollectionBinding().getKey().isNullable() && !getCollectionBinding().isInverse() && !indexIsFormula ) { final String entityName = ( (OneToMany) getCollectionBinding().getElement() ).getReferencedEntityName(); final PersistentClass referenced = getMappingDocument().getMetadataCollector().getEntityBinding( entityName ); final IndexBackref ib = new IndexBackref(); ib.setName( '_' + getCollectionBinding().getOwnerEntityName() + "." + getPluralAttributeSource().getName() + "IndexBackref" ); ib.setUpdateable( false ); ib.setSelectable( false ); ib.setCollectionRole( getCollectionBinding().getRole() ); ib.setEntityName( getCollectionBinding().getOwner().getEntityName() ); ib.setValue( getCollectionBinding().getIndex() ); referenced.addProperty( ib ); } } }
subnode, value, map.isOneToMany(), IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, mappings mto, IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, map.isOneToMany(), mappings );
subnode, value, map.isOneToMany(), IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, mappings ); ManyToOne mto = new ManyToOne( map.getCollectionTable() ); bindManyToOne( subnode, mto, IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, map .isOneToMany(), mappings ); map.setIndex( mto ); component, map.getRole() + ".index", map.isOneToMany(), mappings, inheritedMetas ); bindAny( subnode, any, map.isOneToMany(), mappings ); map.setIndex( any ); if ( map.isOneToMany() && !map.getKey().isNullable() && !map.isInverse() && !indexIsFormula ) { String entityName = ( (OneToMany) map.getElement() ).getReferencedEntityName(); PersistentClass referenced = mappings.getClass( entityName );
subnode, value, map.isOneToMany(), IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, mappings mto, IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, map.isOneToMany(), mappings ); component, map.getRole() + ".index", map.isOneToMany(), mappings, inheritedMetas bindAny( subnode, any, map.isOneToMany(), mappings ); map.setIndex( any ); if ( map.isOneToMany() && !map.getKey().isNullable() && !map.isInverse() && !indexIsFormula ) { String entityName = ( (OneToMany) map.getElement() ).getReferencedEntityName(); PersistentClass referenced = mappings.getClass( entityName );
subnode, value, map.isOneToMany(), IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, mappings mto, IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, map.isOneToMany(), mappings ); component, map.getRole() + ".index", map.isOneToMany(), mappings, inheritedMetas bindAny( subnode, any, map.isOneToMany(), mappings ); map.setIndex( any ); if ( map.isOneToMany() && !map.getKey().isNullable() && !map.isInverse() && !indexIsFormula ) { String entityName = ( (OneToMany) map.getElement() ).getReferencedEntityName(); PersistentClass referenced = mappings.getClass( entityName );
private void makeOneToManyMapKeyColumnNullableIfNotInProperty( final XProperty property) { final org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection; if ( map.isOneToMany() && property.isAnnotationPresent( MapKeyColumn.class ) ) { final Value<?> indexValue = map.getIndex(); if ( indexValue.getColumnSpan() != 1 ) { throw new AssertionFailure( "Map key mapped by @MapKeyColumn does not have 1 column" ); } final MappedColumn mappedColumn = indexValue.getMappedColumns().get( 0 ); if ( mappedColumn.isFormula() ) { throw new AssertionFailure( "Map key mapped by @MapKeyColumn is a Formula" ); } final Column column = (Column) map.getIndex().getMappedColumns().get( 0 ); if ( !column.isNullable() ) { final PersistentClass persistentClass = ( ( OneToMany ) map.getElement() ).getAssociatedClass(); // check if the index column has been mapped by the associated entity to a property; // @MapKeyColumn only maps a column to the primary table for the one-to-many, so we only // need to check "un-joined" properties. if ( !propertyIteratorContainsColumn( persistentClass.getUnjoinedPropertyIterator(), column ) ) { // The index column is not mapped to an associated entity property so we can // safely make the index column nullable. column.setNullable( true ); } } } }
@Override protected void createBackReferences() { super.createBackReferences(); boolean indexIsFormula = false; final List<MappedColumn> mappedColumns = getCollectionBinding().getIndex().getMappedColumns(); for ( MappedColumn mappedColumn : mappedColumns ) { if ( mappedColumn.isFormula() ) { indexIsFormula = true; } } if ( getCollectionBinding().isOneToMany() && !getCollectionBinding().getKey().isNullable() && !getCollectionBinding().isInverse() && !indexIsFormula ) { final String entityName = ( (OneToMany) getCollectionBinding().getElement() ).getReferencedEntityName(); final PersistentClass referenced = getMappingDocument().getMetadataCollector().getEntityBinding( entityName ); final IndexBackref ib = new IndexBackref( metadataBuildingContext ); ib.setName( '_' + getCollectionBinding().getOwnerEntityName() + "." + getPluralAttributeSource().getName() + "IndexBackref" ); ib.setUpdateable( false ); ib.setSelectable( false ); ib.setCollectionRole( getCollectionBinding().getRole() ); ib.setEntityName( getCollectionBinding().getOwner().getEntityName() ); ib.setValue( getCollectionBinding().getIndex() ); referenced.addProperty( ib ); } } }