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());
}
}
}
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;
}
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());
}
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();
}
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);
}
Aggregations