Search in sources :

Example 51 with AnnotationException

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

the class ColumnsBuilder method buildDefaultJoinColumnsForXToOne.

Ejb3JoinColumn[] buildDefaultJoinColumnsForXToOne(XProperty property, PropertyData inferredData) {
    Ejb3JoinColumn[] joinColumns;
    JoinTable joinTableAnn = propertyHolder.getJoinTable(property);
    if (joinTableAnn != null) {
        joinColumns = Ejb3JoinColumn.buildJoinColumns(joinTableAnn.inverseJoinColumns(), null, entityBinder.getSecondaryTables(), propertyHolder, inferredData.getPropertyName(), buildingContext);
        if (StringHelper.isEmpty(joinTableAnn.name())) {
            throw new AnnotationException("JoinTable.name() on a @ToOne association has to be explicit: " + BinderHelper.getPath(propertyHolder, inferredData));
        }
    } else {
        OneToOne oneToOneAnn = property.getAnnotation(OneToOne.class);
        String mappedBy = oneToOneAnn != null ? oneToOneAnn.mappedBy() : null;
        joinColumns = Ejb3JoinColumn.buildJoinColumns(null, mappedBy, entityBinder.getSecondaryTables(), propertyHolder, inferredData.getPropertyName(), buildingContext);
    }
    return joinColumns;
}
Also used : OneToOne(javax.persistence.OneToOne) AnnotationException(org.hibernate.AnnotationException) JoinTable(javax.persistence.JoinTable)

Example 52 with AnnotationException

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

the class AnnotationBinder method bindTypeDef.

private static void bindTypeDef(TypeDef defAnn, MetadataBuildingContext context) {
    Properties params = new Properties();
    for (Parameter param : defAnn.parameters()) {
        params.setProperty(param.name(), param.value());
    }
    if (BinderHelper.isEmptyAnnotationValue(defAnn.name()) && defAnn.defaultForType().equals(void.class)) {
        throw new AnnotationException("Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass " + defAnn.typeClass().getName());
    }
    final String typeBindMessageF = "Binding type definition: %s";
    if (!BinderHelper.isEmptyAnnotationValue(defAnn.name())) {
        if (LOG.isDebugEnabled()) {
            LOG.debugf(typeBindMessageF, defAnn.name());
        }
        context.getMetadataCollector().addTypeDefinition(new TypeDefinition(defAnn.name(), defAnn.typeClass(), null, params));
    }
    if (!defAnn.defaultForType().equals(void.class)) {
        if (LOG.isDebugEnabled()) {
            LOG.debugf(typeBindMessageF, defAnn.defaultForType().getName());
        }
        context.getMetadataCollector().addTypeDefinition(new TypeDefinition(defAnn.defaultForType().getName(), defAnn.typeClass(), new String[] { defAnn.defaultForType().getName() }, params));
    }
}
Also used : Parameter(org.hibernate.annotations.Parameter) AnnotationException(org.hibernate.AnnotationException) Properties(java.util.Properties) TypeDefinition(org.hibernate.boot.model.TypeDefinition)

Example 53 with AnnotationException

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

the class AttributeConverterDescriptorImpl method create.

public static AttributeConverterDescriptor create(AttributeConverterDefinition definition, ClassmateContext classmateContext) {
    final AttributeConverter converter = definition.getAttributeConverter();
    final Class converterClass = converter.getClass();
    final ResolvedType converterType = classmateContext.getTypeResolver().resolve(converterClass);
    final List<ResolvedType> converterParamTypes = converterType.typeParametersFor(AttributeConverter.class);
    if (converterParamTypes == null) {
        throw new AnnotationException("Could not extract type parameter information from AttributeConverter implementation [" + converterClass.getName() + "]");
    } else if (converterParamTypes.size() != 2) {
        throw new AnnotationException("Unexpected type parameter information for AttributeConverter implementation [" + converterClass.getName() + "]; expected 2 parameter types, but found " + converterParamTypes.size());
    }
    return new AttributeConverterDescriptorImpl(converter, definition.isAutoApply(), converterParamTypes.get(0), converterParamTypes.get(1));
}
Also used : AttributeConverter(javax.persistence.AttributeConverter) AnnotationException(org.hibernate.AnnotationException) ResolvedType(com.fasterxml.classmate.ResolvedType)

Example 54 with AnnotationException

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

the class JPAOverriddenAnnotationReader method getInheritance.

private Inheritance getInheritance(Element tree, XMLContext.Default defaults) {
    Element element = tree != null ? tree.element("inheritance") : null;
    if (element != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(Inheritance.class);
        Attribute attr = element.attribute("strategy");
        InheritanceType strategy = InheritanceType.SINGLE_TABLE;
        if (attr != null) {
            String value = attr.getValue();
            if ("SINGLE_TABLE".equals(value)) {
                strategy = InheritanceType.SINGLE_TABLE;
            } else if ("JOINED".equals(value)) {
                strategy = InheritanceType.JOINED;
            } else if ("TABLE_PER_CLASS".equals(value)) {
                strategy = InheritanceType.TABLE_PER_CLASS;
            } else {
                throw new AnnotationException("Unknown InheritanceType in XML: " + value + " (" + SCHEMA_VALIDATION + ")");
            }
        }
        ad.setValue("strategy", strategy);
        return AnnotationFactory.create(ad);
    } else if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(Inheritance.class);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) Attribute(org.dom4j.Attribute) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) Inheritance(javax.persistence.Inheritance) AnnotationException(org.hibernate.AnnotationException) InheritanceType(javax.persistence.InheritanceType)

Example 55 with AnnotationException

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

the class QueryHintDefinition method getCacheMode.

public CacheMode getCacheMode(String query) {
    String hitName = QueryHints.CACHE_MODE;
    String value = (String) hintsMap.get(hitName);
    if (value == null) {
        return null;
    }
    try {
        return CacheMode.interpretExternalSetting(value);
    } catch (MappingException e) {
        throw new AnnotationException("Unknown CacheMode in hint: " + query + ":" + hitName, e);
    }
}
Also used : AnnotationException(org.hibernate.AnnotationException) MappingException(org.hibernate.MappingException)

Aggregations

AnnotationException (org.hibernate.AnnotationException)85 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)15 PersistentClass (org.hibernate.mapping.PersistentClass)14 AnnotatedElement (java.lang.reflect.AnnotatedElement)12 Element (org.dom4j.Element)12 XClass (org.hibernate.annotations.common.reflection.XClass)12 HashMap (java.util.HashMap)11 MappingException (org.hibernate.MappingException)11 XProperty (org.hibernate.annotations.common.reflection.XProperty)11 Property (org.hibernate.mapping.Property)11 SimpleValue (org.hibernate.mapping.SimpleValue)11 Test (org.junit.Test)10 AssertionFailure (org.hibernate.AssertionFailure)9 ArrayList (java.util.ArrayList)8 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)8 Column (org.hibernate.mapping.Column)8 IdClass (javax.persistence.IdClass)7 MapKeyClass (javax.persistence.MapKeyClass)7 Component (org.hibernate.mapping.Component)7 Properties (java.util.Properties)6