Search in sources :

Example 46 with AssertionFailure

use of org.hibernate.AssertionFailure in project hibernate-orm by hibernate.

the class AnnotationBinder method bindDiscriminatorColumnToRootPersistentClass.

private static void bindDiscriminatorColumnToRootPersistentClass(RootClass rootClass, Ejb3DiscriminatorColumn discriminatorColumn, Map<String, Join> secondaryTables, PropertyHolder propertyHolder, MetadataBuildingContext context) {
    if (rootClass.getDiscriminator() == null) {
        if (discriminatorColumn == null) {
            throw new AssertionFailure("discriminator column should have been built");
        }
        discriminatorColumn.setJoins(secondaryTables);
        discriminatorColumn.setPropertyHolder(propertyHolder);
        SimpleValue discriminatorColumnBinding = new SimpleValue(context, rootClass.getTable());
        rootClass.setDiscriminator(discriminatorColumnBinding);
        discriminatorColumn.linkWithValue(discriminatorColumnBinding);
        discriminatorColumnBinding.setTypeName(discriminatorColumn.getDiscriminatorTypeName());
        rootClass.setPolymorphic(true);
        if (LOG.isTraceEnabled()) {
            LOG.tracev("Setting discriminator for entity {0}", rootClass.getEntityName());
        }
    }
}
Also used : AssertionFailure(org.hibernate.AssertionFailure) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 47 with AssertionFailure

use of org.hibernate.AssertionFailure in project hibernate-orm by hibernate.

the class AnnotationBinder method getSuperEntity.

private static PersistentClass getSuperEntity(XClass clazzToProcess, Map<XClass, InheritanceState> inheritanceStatePerClass, MetadataBuildingContext context, InheritanceState inheritanceState) {
    InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity(clazzToProcess, inheritanceStatePerClass);
    PersistentClass superEntity = superEntityState != null ? context.getMetadataCollector().getEntityBinding(superEntityState.getClazz().getName()) : null;
    if (superEntity == null) {
        // check if superclass is not a potential persistent class
        if (inheritanceState.hasParents()) {
            throw new AssertionFailure("Subclass has to be binded after it's mother class: " + superEntityState.getClazz().getName());
        }
    }
    return superEntity;
}
Also used : AssertionFailure(org.hibernate.AssertionFailure) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 48 with AssertionFailure

use of org.hibernate.AssertionFailure in project hibernate-orm by hibernate.

the class AnnotationBinder method bindAny.

private static void bindAny(String cascadeStrategy, Ejb3JoinColumn[] columns, boolean cascadeOnDelete, Nullability nullability, PropertyHolder propertyHolder, PropertyData inferredData, EntityBinder entityBinder, boolean isIdentifierMapper, MetadataBuildingContext buildingContext) {
    org.hibernate.annotations.Any anyAnn = inferredData.getProperty().getAnnotation(org.hibernate.annotations.Any.class);
    if (anyAnn == null) {
        throw new AssertionFailure("Missing @Any annotation: " + BinderHelper.getPath(propertyHolder, inferredData));
    }
    Any value = BinderHelper.buildAnyValue(anyAnn.metaDef(), columns, anyAnn.metaColumn(), inferredData, cascadeOnDelete, nullability, propertyHolder, entityBinder, anyAnn.optional(), buildingContext);
    PropertyBinder binder = new PropertyBinder();
    binder.setName(inferredData.getPropertyName());
    binder.setValue(value);
    binder.setLazy(anyAnn.fetch() == FetchType.LAZY);
    // binder.setCascade(cascadeStrategy);
    if (isIdentifierMapper) {
        binder.setInsertable(false);
        binder.setUpdatable(false);
    } else {
        binder.setInsertable(columns[0].isInsertable());
        binder.setUpdatable(columns[0].isUpdatable());
    }
    binder.setAccessType(inferredData.getDefaultAccess());
    binder.setCascade(cascadeStrategy);
    Property prop = binder.makeProperty();
    // composite FK columns are in the same table so its OK
    propertyHolder.addProperty(prop, columns, inferredData.getDeclaringClass());
}
Also used : AssertionFailure(org.hibernate.AssertionFailure) PropertyBinder(org.hibernate.cfg.annotations.PropertyBinder) Any(org.hibernate.mapping.Any) ManyToAny(org.hibernate.annotations.ManyToAny) Property(org.hibernate.mapping.Property) XProperty(org.hibernate.annotations.common.reflection.XProperty)

Example 49 with AssertionFailure

use of org.hibernate.AssertionFailure in project hibernate-orm by hibernate.

the class AnnotationBinder method buildIdGenerator.

private static IdentifierGeneratorDefinition buildIdGenerator(java.lang.annotation.Annotation generatorAnn, MetadataBuildingContext context) {
    if (generatorAnn == null) {
        return null;
    }
    IdentifierGeneratorDefinition.Builder definitionBuilder = new IdentifierGeneratorDefinition.Builder();
    if (context.getMappingDefaults().getImplicitSchemaName() != null) {
        definitionBuilder.addParam(PersistentIdentifierGenerator.SCHEMA, context.getMappingDefaults().getImplicitSchemaName());
    }
    if (context.getMappingDefaults().getImplicitCatalogName() != null) {
        definitionBuilder.addParam(PersistentIdentifierGenerator.CATALOG, context.getMappingDefaults().getImplicitCatalogName());
    }
    if (generatorAnn instanceof TableGenerator) {
        context.getBuildingOptions().getIdGenerationTypeInterpreter().interpretTableGenerator((TableGenerator) generatorAnn, definitionBuilder);
        if (LOG.isTraceEnabled()) {
            LOG.tracev("Add table generator with name: {0}", definitionBuilder.getName());
        }
    } else if (generatorAnn instanceof SequenceGenerator) {
        context.getBuildingOptions().getIdGenerationTypeInterpreter().interpretSequenceGenerator((SequenceGenerator) generatorAnn, definitionBuilder);
        if (LOG.isTraceEnabled()) {
            LOG.tracev("Add sequence generator with name: {0}", definitionBuilder.getName());
        }
    } else if (generatorAnn instanceof GenericGenerator) {
        GenericGenerator genGen = (GenericGenerator) generatorAnn;
        definitionBuilder.setName(genGen.name());
        definitionBuilder.setStrategy(genGen.strategy());
        Parameter[] params = genGen.parameters();
        for (Parameter parameter : params) {
            definitionBuilder.addParam(parameter.name(), parameter.value());
        }
        if (LOG.isTraceEnabled()) {
            LOG.tracev("Add generic generator with name: {0}", definitionBuilder.getName());
        }
    } else {
        throw new AssertionFailure("Unknown Generator annotation: " + generatorAnn);
    }
    return definitionBuilder.build();
}
Also used : AssertionFailure(org.hibernate.AssertionFailure) SequenceGenerator(javax.persistence.SequenceGenerator) IdentifierGeneratorDefinition(org.hibernate.boot.model.IdentifierGeneratorDefinition) Parameter(org.hibernate.annotations.Parameter) TableGenerator(javax.persistence.TableGenerator) GenericGenerator(org.hibernate.annotations.GenericGenerator)

Example 50 with AssertionFailure

use of org.hibernate.AssertionFailure in project hibernate-orm by hibernate.

the class Ejb3JoinColumn method copyReferencedStructureAndCreateDefaultJoinColumns.

public void copyReferencedStructureAndCreateDefaultJoinColumns(PersistentClass referencedEntity, Iterator columnIterator, SimpleValue value) {
    if (!isNameDeferred()) {
        throw new AssertionFailure("Building implicit column but the column is not implicit");
    }
    while (columnIterator.hasNext()) {
        Column synthCol = (Column) columnIterator.next();
        this.linkValueUsingDefaultColumnNaming(synthCol, referencedEntity, value);
    }
    // reset for the future
    setMappingColumn(null);
}
Also used : AssertionFailure(org.hibernate.AssertionFailure) JoinColumn(javax.persistence.JoinColumn) Column(org.hibernate.mapping.Column) PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn)

Aggregations

AssertionFailure (org.hibernate.AssertionFailure)56 Serializable (java.io.Serializable)11 EntityEntry (org.hibernate.engine.spi.EntityEntry)11 Property (org.hibernate.mapping.Property)10 AnnotationException (org.hibernate.AnnotationException)9 PersistentClass (org.hibernate.mapping.PersistentClass)9 SimpleValue (org.hibernate.mapping.SimpleValue)7 EntityPersister (org.hibernate.persister.entity.EntityPersister)7 SQLException (java.sql.SQLException)6 HashMap (java.util.HashMap)6 HibernateException (org.hibernate.HibernateException)6 PreparedStatement (java.sql.PreparedStatement)5 Column (org.hibernate.mapping.Column)5 Component (org.hibernate.mapping.Component)5 Join (org.hibernate.mapping.Join)5 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)5 Iterator (java.util.Iterator)4 Map (java.util.Map)4 XProperty (org.hibernate.annotations.common.reflection.XProperty)4 EntityDataAccess (org.hibernate.cache.spi.access.EntityDataAccess)4