public Value getHibernateValue() { return ( (Map) getPropertyMapping().getValue() ).getIndex(); }
public void createAllKeys() throws MappingException { super.createAllKeys(); if ( !isInverse() ) { getIndex().createForeignKey(); } }
private Type getMapKeyType(Property prop) { Value value = prop.getValue(); assertEquals( Map.class, value.getClass() ); Map map = (Map) value; return map.getIndex().getType(); }
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 ); } } } }
@Test @TestForIssue( jiraKey = "HHH-8630" ) public void testIt() { final PersistentClass entityBinding = metadata().getEntityBinding( AggregatedTypeValue.class.getName() ); final Property attributesBinding = entityBinding.getProperty( "attributes" ); final org.hibernate.mapping.Map attributesMap = (org.hibernate.mapping.Map) attributesBinding.getValue(); final SimpleValue mapKey = assertTyping( SimpleValue.class, attributesMap.getIndex() ); final BasicType mapKeyType = assertTyping( BasicType.class, mapKey.getType() ); assertTrue( String.class.equals( mapKeyType.getReturnedClass() ) ); // let's also make sure the @MapKeyColumn got applied assertThat( mapKey.getColumnSpan(), is(1) ); final org.hibernate.mapping.Column mapKeyColumn = assertTyping( org.hibernate.mapping.Column .class, mapKey.getColumnIterator().next() ); assertThat( mapKeyColumn.getName(), equalTo( "attribute_name" ) ); }
@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 ); } } }
final Value keyValue = ( (Map) value ).getIndex(); final org.hibernate.type.Type keyType = keyValue.getType();
public Value getValue() { return ( (Map) getPropertyMapping().getValue() ).getIndex(); }
public void createAllKeys() throws MappingException { super.createAllKeys(); if ( !isInverse() ) { getIndex().createForeignKey(); } }
public void createAllKeys() throws MappingException { super.createAllKeys(); if ( !isInverse() ) getIndex().createForeignKey(); }
public void createAllKeys() throws MappingException { super.createAllKeys(); if ( !isInverse() ) getIndex().createForeignKey(); }
public void createAllKeys() throws MappingException { super.createAllKeys(); if ( !isInverse() ) getIndex().createForeignKey(); }
public void createAllKeys() throws MappingException { super.createAllKeys(); if ( !isInverse() ) getIndex().createForeignKey(); }
private Value resolveContainedValue(org.hibernate.mapping.Collection collectionValue, Class<? extends ContainerExtractor> extractorClass) { if ( BuiltinContainerExtractor.ARRAY.getType().equals( extractorClass ) ) { if ( collectionValue instanceof org.hibernate.mapping.Array ) { return collectionValue.getElement(); } } else if ( BuiltinContainerExtractor.MAP_VALUE.getType().equals( extractorClass ) ) { if ( collectionValue instanceof org.hibernate.mapping.Map ) { return collectionValue.getElement(); } } else if ( BuiltinContainerExtractor.MAP_KEY.getType().equals( extractorClass ) ) { if ( collectionValue instanceof org.hibernate.mapping.Map ) { /* * Do not let ORM confuse you: getKey() doesn't return the value of the map key, * but the value of the foreign key to the targeted entity... */ return ( (org.hibernate.mapping.Map) collectionValue ).getIndex(); } } else if ( BuiltinContainerExtractor.COLLECTION.getType().equals( extractorClass ) ) { return collectionValue.getElement(); } throw log.invalidContainerExtractorForDirtyChecking( collectionValue.getClass(), extractorClass ); }
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 ); } } } }
final Value keyValue = ((Map)value).getIndex(); final org.hibernate.type.Type keyType = keyValue.getType();
@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 ); } } }