Search in sources :

Example 6 with AnnotationException

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

the class PkDrivenByDefaultMapsIdSecondPass method doSecondPass.

public void doSecondPass(Map persistentClasses) throws MappingException {
    PersistentClass referencedEntity = (PersistentClass) persistentClasses.get(referencedEntityName);
    if (referencedEntity == null) {
        throw new AnnotationException("Unknown entity name: " + referencedEntityName);
    }
    TableBinder.linkJoinColumnWithValueOverridingNameIfImplicit(referencedEntity, referencedEntity.getKey().getColumnIterator(), columns, value);
}
Also used : AnnotationException(org.hibernate.AnnotationException) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 7 with AnnotationException

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

the class JPAOverriddenAnnotationReader method getTemporal.

private void getTemporal(List<Annotation> annotationList, Element element) {
    Element subElement = element != null ? element.element("temporal") : null;
    if (subElement != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(Temporal.class);
        String temporal = subElement.getTextTrim();
        if ("DATE".equalsIgnoreCase(temporal)) {
            ad.setValue("value", TemporalType.DATE);
        } else if ("TIME".equalsIgnoreCase(temporal)) {
            ad.setValue("value", TemporalType.TIME);
        } else if ("TIMESTAMP".equalsIgnoreCase(temporal)) {
            ad.setValue("value", TemporalType.TIMESTAMP);
        } else if (StringHelper.isNotEmpty(temporal)) {
            throw new AnnotationException("Unknown TemporalType: " + temporal + ". " + SCHEMA_VALIDATION);
        }
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) AnnotationException(org.hibernate.AnnotationException)

Example 8 with AnnotationException

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

the class JPAOverriddenAnnotationReader method addTargetClass.

private void addTargetClass(Element element, AnnotationDescriptor ad, String nodeName, XMLContext.Default defaults) {
    String className = element.attributeValue(nodeName);
    if (className != null) {
        Class clazz;
        try {
            clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(className, defaults));
        } catch (ClassLoadingException e) {
            throw new AnnotationException("Unable to find " + element.getPath() + " " + nodeName + ": " + className, e);
        }
        ad.setValue(getJavaAttributeNameFromXMLOne(nodeName), clazz);
    }
}
Also used : ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) AnnotationException(org.hibernate.AnnotationException) MapKeyClass(javax.persistence.MapKeyClass) IdClass(javax.persistence.IdClass)

Example 9 with AnnotationException

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

the class OrmVersionTest method testInvalidOrm1.

@Test
public void testInvalidOrm1() {
    PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl("invalid-orm1-test", "1.0").addMappingFileName("org/hibernate/jpa/test/jee/invalid-orm-1.xml");
    HibernatePersistenceProvider hp = new HibernatePersistenceProvider();
    EntityManagerFactory emf = null;
    try {
        emf = hp.createContainerEntityManagerFactory(pui, Collections.EMPTY_MAP);
        Assert.fail("expecting 'invalid content' error");
    } catch (InvalidMappingException | AnnotationException expected) {
    // expected condition
    } catch (PersistenceException expected) {
    // expected condition
    } finally {
        if (emf != null) {
            emf.close();
        }
    }
}
Also used : InvalidMappingException(org.hibernate.InvalidMappingException) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceException(javax.persistence.PersistenceException) HibernatePersistenceProvider(org.hibernate.jpa.HibernatePersistenceProvider) AnnotationException(org.hibernate.AnnotationException) Test(org.junit.Test)

Example 10 with AnnotationException

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

the class BasicHibernateAnnotationsTest method testTypeDefWithoutNameAndDefaultForTypeAttributes.

@Test
public void testTypeDefWithoutNameAndDefaultForTypeAttributes() {
    SessionFactory sf = null;
    StandardServiceRegistryImpl ssr = null;
    try {
        Configuration config = new Configuration();
        config.addAnnotatedClass(LocalContactDetails.class);
        ssr = ServiceRegistryBuilder.buildServiceRegistry(config.getProperties());
        sf = config.buildSessionFactory(ssr);
        fail("Did not throw expected exception");
    } catch (AnnotationException ex) {
        assertEquals("Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass org.hibernate.test.annotations.entity.PhoneNumberType", ex.getMessage());
    } finally {
        if (ssr != null) {
            ssr.destroy();
        }
        if (sf != null) {
            sf.close();
        }
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) AnnotationException(org.hibernate.AnnotationException) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) Test(org.junit.Test)

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