use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class AttributeConverterTest method testErrorInstantiatingConverterClass.
@Test
public void testErrorInstantiatingConverterClass() {
Configuration cfg = new Configuration();
try {
cfg.addAttributeConverter(BlowsUpConverter.class);
fail("expecting an exception");
} catch (AnnotationException e) {
assertNotNull(e.getCause());
assertTyping(BlewUpException.class, e.getCause());
}
}
use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class InvalidEnumeratedJavaTypeTest method testInvalidMapping.
@Test
public void testInvalidMapping() {
MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(TheEntity.class);
try {
metadataSources.buildMetadata();
fail("Was expecting failure");
} catch (AnnotationException ignore) {
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class SpreadNaturalIdTest method testSpreadNaturalIdDeclarationGivesMappingException.
@Test
@SuppressWarnings("EmptyCatchBlock")
public void testSpreadNaturalIdDeclarationGivesMappingException() {
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Principal.class).addAnnotatedClass(User.class);
try {
metadataSources.buildMetadata();
fail("Expected binders to throw an exception");
} catch (AnnotationException expected) {
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class InFlightMetadataCollectorImpl method buildRecursiveOrderedFkSecondPasses.
/**
* Recursively builds a list of FkSecondPass instances ready to be processed in this order.
* Checking all dependencies recursively seems quite expensive, but the original code just relied
* on some sort of table name sorting which failed in certain circumstances.
* <p/>
* See <tt>ANN-722</tt> and <tt>ANN-730</tt>
*
* @param orderedFkSecondPasses The list containing the <code>FkSecondPass<code> instances ready
* for processing.
* @param isADependencyOf Our lookup data structure to determine dependencies between tables
* @param startTable Table name to start recursive algorithm.
* @param currentTable The current table name used to check for 'new' dependencies.
*/
private void buildRecursiveOrderedFkSecondPasses(List<FkSecondPass> orderedFkSecondPasses, Map<String, Set<FkSecondPass>> isADependencyOf, String startTable, String currentTable) {
Set<FkSecondPass> dependencies = isADependencyOf.get(currentTable);
// bottom out
if (dependencies == null || dependencies.size() == 0) {
return;
}
for (FkSecondPass sp : dependencies) {
String dependentTable = sp.getValue().getTable().getQualifiedTableName().render();
if (dependentTable.compareTo(startTable) == 0) {
throw new AnnotationException("Foreign key circularity dependency involving the following tables: " + startTable + ", " + dependentTable);
}
buildRecursiveOrderedFkSecondPasses(orderedFkSecondPasses, isADependencyOf, startTable, dependentTable);
if (!orderedFkSecondPasses.contains(sp)) {
orderedFkSecondPasses.add(0, sp);
}
}
}
use of org.hibernate.AnnotationException in project hibernate-orm by hibernate.
the class AnnotationBinder method bindIdClass.
private static void bindIdClass(String generatorType, String generatorName, PropertyData inferredData, PropertyData baseInferredData, Ejb3Column[] columns, PropertyHolder propertyHolder, boolean isComposite, AccessType propertyAccessor, EntityBinder entityBinder, boolean isEmbedded, boolean isIdentifierMapper, MetadataBuildingContext buildingContext, Map<XClass, InheritanceState> inheritanceStatePerClass) {
/*
* Fill simple value and property since and Id is a property
*/
PersistentClass persistentClass = propertyHolder.getPersistentClass();
if (!(persistentClass instanceof RootClass)) {
throw new AnnotationException("Unable to define/override @Id(s) on a subclass: " + propertyHolder.getEntityName());
}
RootClass rootClass = (RootClass) persistentClass;
String persistentClassName = rootClass.getClassName();
SimpleValue id;
final String propertyName = inferredData.getPropertyName();
if (isComposite) {
id = fillComponent(propertyHolder, inferredData, baseInferredData, propertyAccessor, false, entityBinder, isEmbedded, isIdentifierMapper, false, buildingContext, inheritanceStatePerClass);
Component componentId = (Component) id;
componentId.setKey(true);
if (rootClass.getIdentifier() != null) {
throw new AnnotationException(componentId.getComponentClassName() + " must not have @Id properties when used as an @EmbeddedId");
}
if (componentId.getPropertySpan() == 0) {
throw new AnnotationException(componentId.getComponentClassName() + " has no persistent id property");
}
// tuplizers
XProperty property = inferredData.getProperty();
setupComponentTuplizer(property, componentId);
} else {
for (Ejb3Column column : columns) {
// this is an id
column.forceNotNull();
}
SimpleValueBinder value = new SimpleValueBinder();
value.setPropertyName(propertyName);
value.setReturnedClassName(inferredData.getTypeName());
value.setColumns(columns);
value.setPersistentClassName(persistentClassName);
value.setBuildingContext(buildingContext);
value.setType(inferredData.getProperty(), inferredData.getClassOrElement(), persistentClassName, null);
value.setAccessType(propertyAccessor);
id = value.make();
}
rootClass.setIdentifier(id);
SecondPass secondPass = new IdGeneratorResolverSecondPass(id, inferredData.getProperty(), generatorType, generatorName, buildingContext);
buildingContext.getMetadataCollector().addSecondPass(secondPass);
if (isEmbedded) {
rootClass.setEmbeddedIdentifier(inferredData.getPropertyClass() == null);
} else {
PropertyBinder binder = new PropertyBinder();
binder.setName(propertyName);
binder.setValue(id);
binder.setAccessType(inferredData.getDefaultAccess());
binder.setProperty(inferredData.getProperty());
Property prop = binder.makeProperty();
rootClass.setIdentifierProperty(prop);
// if the id property is on a superclass, update the metamodel
final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(inferredData.getDeclaringClass(), inheritanceStatePerClass, buildingContext);
if (superclass != null) {
superclass.setDeclaredIdentifierProperty(prop);
} else {
// we know the property is on the actual entity
rootClass.setDeclaredIdentifierProperty(prop);
}
}
}
Aggregations