Refine search
/** * @deprecated See mainly {@link #buildEntityBasedAttribute} */ @Deprecated public static StandardProperty buildStandardProperty(Property property, boolean lazyAvailable) { final Type type = property.getValue().getType(); // we need to dirty check collections, since they can cause an owner // version number increment // we need to dirty check many-to-ones with not-found="ignore" in order // to update the cache (not the database), since in this case a null // entity reference can lose information boolean alwaysDirtyCheck = type.isAssociationType() && ( (AssociationType) type ).isAlwaysDirtyChecked(); return new StandardProperty( property.getName(), type, lazyAvailable && property.isLazy(), property.isInsertable(), property.isUpdateable(), property.getValueGenerationStrategy(), property.isOptional(), alwaysDirtyCheck || property.isUpdateable(), property.isOptimisticLocked(), property.getCascadeStyle(), property.getValue().getFetchMode() ); }
PersistentClass targetPropertyPersistentClass, MetadataBuildingContext buildingContext) { Value element = collection.getElement(); String fromAndWhere = null; if ( !( element instanceof OneToMany ) ) { referencedPropertyName = collection.getReferencedPropertyName(); referencedEntityColumns = associatedClass.getIdentifier().getColumnIterator(); Property referencedProperty = associatedClass.getRecursiveProperty( referencedPropertyName ); referencedEntityColumns = referencedProperty.getColumnIterator(); associatedClass.getTable().getName(), element.getColumnIterator(), referencedEntityColumns ); .getQualifiedTableName() .toString(), element.getColumnIterator(), associatedClass.getIdentifier().getColumnIterator() ); while ( properties.hasNext() ) { Property current = (Property) properties.next(); Property newProperty = new Property(); newProperty.setCascade( current.getCascade() );
private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) { while ( propertyIterator.hasNext() ) { Property prop = (Property) propertyIterator.next(); String propname = path == null ? prop.getName() : path + "." + prop.getName(); if ( prop.isComposite() ) { Component component = (Component) prop.getValue(); Iterator compProps = component.getPropertyIterator(); internalInitSubclassPropertyAliasesMap( propname, compProps ); } else { String[] aliases = new String[prop.getColumnSpan()]; String[] cols = new String[prop.getColumnSpan()]; Iterator colIter = prop.getColumnIterator(); int l = 0; while ( colIter.hasNext() ) { Selectable thing = (Selectable) colIter.next(); aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() ); cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas? l++; } subclassPropertyAliases.put( propname, aliases ); subclassPropertyColumnNames.put( propname, cols ); } } }
public static void createUniqueConstraint(Value value) { Iterator iter = value.getColumnIterator(); ArrayList cols = new ArrayList(); while ( iter.hasNext() ) { cols.add( iter.next() ); } value.getTable().createUniqueKey( cols ); }
public void validate(Mapping mapping) throws MappingException { assert getKey() != null : "Collection key not bound : " + getRole(); assert getElement() != null : "Collection element not bound : " + getRole(); if ( !getKey().isValid( mapping ) ) { throw new MappingException( "collection foreign key mapping has wrong number of columns: " + getRole() + " type: " + getKey().getType().getName() ); } if ( !getElement().isValid( mapping ) ) { throw new MappingException( "collection element mapping has wrong number of columns: " + getRole() + " type: " + getElement().getType().getName() ); } checkColumnDuplication(); }
if ( persistentClass.hasPojoRepresentation() ) { rowIdName = persistentClass.getRootTable().getRowId(); versionColumnName = ( ( Column ) persistentClass.getVersion().getColumnIterator().next() ).getQuotedName( factory.getDialect() ); thisClassProperties.add( prop ); while ( colIter.hasNext() ) { Selectable thing = ( Selectable ) colIter.next(); colAliases[k] = thing.getAlias( prop.getValue().getTable() ); colNames[k] = thing.getTemplate( factory.getDialect() ); if ( thing.isFormula() ) { lazyTypes.add( prop.getValue().getType() ); lazyColAliases.add( colAliases ); propertyColumnUpdateable[i] = prop.getValue().getColumnUpdateability(); propertyColumnInsertable[i] = prop.getValue().getColumnInsertability(); propertyUniqueness[i] = prop.getValue().isAlternateUniqueKey(); columns.add( colName ); cols[l] = colName; aliases.add( thing.getAlias( prop.getValue().getTable() ) ); joinedFetchesList.add( prop.getValue().getFetchMode() );
collectionType = collectionBinding.getCollectionType(); navigableRole = new NavigableRole( collectionBinding.getRole() ); fetchMode = collectionBinding.getElement().getFetchMode(); elementType = collectionBinding.getElement().getType(); int elementSpan = collectionBinding.getElement().getColumnSpan(); elementColumnAliases = new String[elementSpan]; elementColumnNames = new String[elementSpan]; boolean hasNotNullableColumns = false; int j = 0; iter = collectionBinding.getElement().getColumnIterator(); while ( iter.hasNext() ) { Selectable selectable = (Selectable) iter.next(); indexType = indexedCollection.getIndex().getType(); int indexSpan = indexedCollection.getIndex().getColumnSpan(); boolean[] indexColumnInsertability = indexedCollection.getIndex().getColumnInsertability(); boolean[] indexColumnUpdatability = indexedCollection.getIndex().getColumnUpdateability(); iter = indexedCollection.getIndex().getColumnIterator(); indexColumnNames = new String[indexSpan]; indexFormulaTemplates = new String[indexSpan]; );
this.navigableRole = new NavigableRole( persistentClass.getEntityName() ); final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect(); identifierAliases = new String[identifierColumnSpan]; rowIdName = persistentClass.getRootTable().getRowId(); while ( colIter.hasNext() ) { Selectable thing = (Selectable) colIter.next(); colAliases[k] = thing.getAlias( dialect, prop.getValue().getTable() ); if ( thing.isFormula() ) { foundFormula = true; lazyTypes.add( prop.getValue().getType() ); lazyColAliases.add( colAliases ); propertyColumnUpdateable[i] = prop.getValue().getColumnUpdateability(); propertyColumnInsertable[i] = prop.getValue().getColumnInsertability(); propertyUniqueness[i] = prop.getValue().isAlternateUniqueKey(); columns.add( colName ); cols[l] = colName; aliases.add( thing.getAlias( dialect, prop.getValue().getTable() ) ); joinedFetchesList.add( prop.getValue().getFetchMode() );
final Selectable selectable = discriminatorMapping.getColumnIterator().next(); if ( Formula.class.isInstance( selectable ) ) { throw new MappingException( "Discriminator formulas on joined inheritance hierarchies not supported at this time" ); final Column column = (Column) selectable; explicitDiscriminatorColumnName = column.getQuotedName( factory.getDialect() ); discriminatorAlias = column.getAlias( factory.getDialect(), persistentClass.getRootTable() ); discriminatorType = (DiscriminatorType) persistentClass.getDiscriminator().getType(); keyColumnReaders.add( keyColReaders ); keyColumnReaderTemplates.add( keyColReaderTemplates ); cascadeDeletes.add( key.isCascadeDeleteEnabled() && factory.getDialect().supportsCascadeDelete() ); int joinIdColumnSpan = key.getColumnSpan(); while ( iter.hasNext() ) { Property prop = (Property) iter.next(); String tabname = prop.getValue().getTable().getQualifiedName( factory.getDialect(), factory.getSettings().getDefaultCatalogName(), while ( iter.hasNext() ) { Property prop = (Property) iter.next(); Table tab = prop.getValue().getTable(); propTableNumbers.add( tabnum );
deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[joinSpan]; customSQLInsert[0] = persistentClass.getCustomSQLInsert(); : join.getCustomSQLDeleteCheckStyle(); Selectable selectable = (Selectable) discrimValue.getColumnIterator().next(); if ( discrimValue.hasFormula() ) { Formula formula = (Formula) selectable; discriminatorFormula = formula.getFormula(); discriminatorFormulaTemplate = null; discriminatorType = persistentClass.getDiscriminator().getType(); discriminatorInsertable = persistentClass.isDiscriminatorInsertable() && !discrimValue.hasFormula(); try { DiscriminatorType dtype = (DiscriminatorType) discriminatorType; throw new MappingException( "Illegal discriminator type: " + discriminatorType.getName() ); prop.getPersistentClass().getEntityName() + '.' + prop.getName(), join ); throw new MappingException( "Illegal discriminator type: " + discriminatorType.getName() );
LOG.debugf( "Retrieving property %s.%s", associatedClass.getEntityName(), mappedByProperty ); mappedByColumns = element.getColumnIterator(); mappedByColumns = property.getValue().getColumnIterator(); idColumns = referencedEntity.getKey().getColumnIterator(); idColumns = referencedEntity.getIdentifier().getColumnIterator(); Collection collection = (Collection) referencedEntity.getRecursiveProperty( propertyName ) .getValue(); referencedPropertyName = collection.getReferencedPropertyName(); if ( Ejb3JoinColumn.NO_REFERENCE == fkEnum ) { if ( columns.length != referencedEntity.getIdentifier().getColumnSpan() ) { throw new AnnotationException( "A Foreign key refering " + referencedEntity.getEntityName()
ManyToAny anyAnn = property.getAnnotation( ManyToAny.class ); if ( LOG.isDebugEnabled() ) { String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); if ( isCollectionOfEntities && unique ) { LOG.debugf("Binding a OneToMany: %s through an association table", path); String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); throw new AnnotationException( "Use of @OneToMany or @ManyToMany targeting an unmapped class: " + path + "[" + collType + "]" String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); throw new AnnotationException( "@JoinTable is mandatory when @ManyToAny is used: " + path otherSideProperty = collectionEntity.getRecursiveProperty( joinColumns[0].getMappedBy() ); if ( otherSideProperty.getValue() instanceof Collection ) { table = ( (Collection) otherSideProperty.getValue() ).getCollectionTable(); table = otherSideProperty.getValue().getTable(); collValue.setCollectionTable( table ); String entityName = collectionEntity.getEntityName(); for (Ejb3JoinColumn column : joinColumns) {
String inverseForeignKeyNameExpected) { final org.hibernate.mapping.Collection collection = metadata().getCollectionBinding( ownerEntityClass.getName() + '.' + ownerCollectionPropertyName ); final org.hibernate.mapping.Table table = collection.getCollectionTable(); assertEquals( expectedCollectionTableName, table.getName() ); ); assertEquals ( 1, ownerCollection.getOwner().getKey().getColumnSpan() ); assertEquals( ownerForeignKeyNameExpected, ownerCollection.getKey().getColumnIterator().next().getText() ); final EntityType associatedEntityType = (EntityType) ownerCollection.getElement().getType(); final PersistentClass associatedPersistentClass = metadata().getEntityBinding( associatedEntityType.getAssociatedEntityName() ); assertEquals( 1, associatedPersistentClass.getKey().getColumnSpan() ); if ( inverseCollectionPropertyName != null ) { final org.hibernate.mapping.Collection inverseCollection = metadata().getCollectionBinding( associatedPersistentClass.getEntityName() + '.' + inverseCollectionPropertyName ); assertEquals( for ( Iterator it=ownerCollection.getCollectionTable().getForeignKeyIterator(); it.hasNext(); ) { final ForeignKey fk = (ForeignKey) it.next(); assertSame( ownerCollection.getCollectionTable(), fk.getTable() );
protected void validateCustomerIndustries(Metadata metadata) { final Collection collectionBinding = metadata.getCollectionBinding( Customer.class.getName() + ".industries" ); assertNotNull( collectionBinding ); validateCustomerIndustriesTableName( collectionBinding.getCollectionTable().getQuotedName() ); assertEquals( 1, collectionBinding.getKey().getColumnSpan() ); validateCustomerIndustriesKeyColumn( (Column) collectionBinding.getKey().getColumnIterator().next() ); assertEquals( 1, collectionBinding.getElement().getColumnSpan() ); validateCustomerIndustriesElementColumn( (Column) collectionBinding.getElement().getColumnIterator().next() ); }
LOG.trace( "Starting attribute metadata determination [" + attributeContext.getPropertyMapping() .getName() + "]" ); final Member member = memberResolver.resolveMember( attributeContext ); LOG.trace( " Determined member [" + member + "]" ); final Value value = attributeContext.getPropertyMapping().getValue(); final org.hibernate.type.Type type = value.getType(); LOG.trace( " Determined type [name=" + type.getName() + ", class=" + type.getClass().getName() + "]" ); if ( type.isAnyType() ) { else if ( type.isAssociationType() ) { if ( type.isEntityType() ) { final Value elementValue = collValue.getElement(); final org.hibernate.type.Type elementType = elementValue.getType(); final org.hibernate.type.Type keyType = keyValue.getType(); if ( keyType.isAnyType() ) { else if ( attributeContext.getPropertyMapping().isComposite() ) {
Property property, boolean lazyAvailable) { String mappedUnsavedValue = ( (KeyValue) property.getValue() ).getNullValue(); (VersionType) property.getType(), getConstructor( property.getPersistentClass() ) ); attributeNumber, property.getName(), property.getValue().getType(), new BaselineAttributeInformation.Builder() .setLazy( lazy )
private void createForeignKeys() throws MappingException { // if ( !isInverse() ) { // for inverse collections, let the "other end" handle it if ( referencedPropertyName == null ) { getElement().createForeignKey(); key.createForeignKeyOfEntity( getOwner().getEntityName() ); } // } }
@Override protected void visitProperty(PersistentClass clazz, Property property, IssueCollector collector) { Value value = property.getValue(); if(value instanceof Collection) { Collection col = (Collection) value; if(col.getCacheConcurrencyStrategy()!=null) { // caching is enabled if (!col.getElement().isSimpleValue()) { String entityName = (String) col.getElement().accept( new EntityNameFromValueVisitor() ); if(entityName!=null) { PersistentClass classMapping = getMetadata().getEntityBinding(entityName); if(classMapping.getCacheConcurrencyStrategy()==null) { collector.reportIssue( new Issue("CACHE_COLLECTION_NONCACHABLE_TARGET", Issue.HIGH_PRIORITY, "Entity '" + classMapping.getEntityName() +"' is referenced from the cache-enabled collection '" + col.getRole() + "' without the entity being cachable")); } } } } } } }
@SuppressWarnings({"unchecked"}) private String searchMappedBy(PersistentClass referencedClass, Collection collectionValue) { final Iterator<Property> assocClassProps = referencedClass.getPropertyIterator(); while ( assocClassProps.hasNext() ) { final Property property = assocClassProps.next(); if ( Tools.iteratorsContentEqual( property.getValue().getColumnIterator(), collectionValue.getKey().getColumnIterator() ) ) { return property.getName(); } } // HHH-7625 // Support ToOne relations with mappedBy that point to an @IdClass key property. return searchMappedByKey( referencedClass, collectionValue ); }
@Test @FailureExpected( jiraKey = "HHH-9089" ) public void testEnumTypeInterpretation() { StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); try { final Metadata metadata = new MetadataSources( ssr ) .addAnnotatedClass( Customer.class ) .buildMetadata(); PersistentClass classMetadata = metadata.getEntityBinding( Customer.class.getName() ); Property investmentsProperty = classMetadata.getProperty( "investments" ); Collection investmentsValue = (Collection) investmentsProperty.getValue(); Component investmentMetadata = (Component) investmentsValue.getElement(); Value descriptionValue = investmentMetadata.getProperty( "description" ).getValue(); assertEquals( 1, descriptionValue.getColumnSpan() ); Column selectable = (Column) descriptionValue.getColumnIterator().next(); assertEquals( 500, selectable.getLength() ); Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue(); SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue(); CustomType currencyType = (CustomType) currencyMetadata.getType(); int[] currencySqlTypes = currencyType.sqlTypes( metadata ); assertEquals( 1, currencySqlTypes.length ); assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); } } }