Search in sources :

Example 46 with MappingException

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

the class FromElementType method getPropertyType.

/**
	 * Returns the type of a property, given it's name (the last part) and the full path.
	 *
	 * @param propertyName The last part of the full path to the property.
	 *
	 * @return The type.
	 *
	 * @0param getPropertyPath The full property path.
	 */
public Type getPropertyType(String propertyName, String propertyPath) {
    checkInitialized();
    Type type = null;
    //      we'd need to "fall through" to using the property mapping.
    if (persister != null && propertyName.equals(propertyPath) && propertyName.equals(persister.getIdentifierPropertyName())) {
        type = persister.getIdentifierType();
    } else {
        // Otherwise, use the property mapping.
        PropertyMapping mapping = getPropertyMapping(propertyName);
        type = mapping.toType(propertyPath);
    }
    if (type == null) {
        throw new MappingException("Property " + propertyName + " does not exist in " + ((queryableCollection == null) ? "class" : "collection") + " " + ((queryableCollection == null) ? fromElement.getClassName() : queryableCollection.getRole()));
    }
    return type;
}
Also used : EntityType(org.hibernate.type.EntityType) Type(org.hibernate.type.Type) PropertyMapping(org.hibernate.persister.entity.PropertyMapping) CollectionPropertyMapping(org.hibernate.persister.collection.CollectionPropertyMapping) MappingException(org.hibernate.MappingException)

Example 47 with MappingException

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

the class TypeFactory method custom.

/**
	 * @deprecated Only for use temporary use by {@link org.hibernate.Hibernate}
	 */
@Deprecated
public static CustomType custom(Class<UserType> typeClass, Properties parameters, TypeScope scope) {
    try {
        UserType userType = typeClass.newInstance();
        injectParameters(userType, parameters);
        return new CustomType(userType);
    } catch (Exception e) {
        throw new MappingException("Unable to instantiate custom type: " + typeClass.getName(), e);
    }
}
Also used : CompositeUserType(org.hibernate.usertype.CompositeUserType) UserType(org.hibernate.usertype.UserType) MappingException(org.hibernate.MappingException) HibernateException(org.hibernate.HibernateException) MappingException(org.hibernate.MappingException)

Example 48 with MappingException

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

the class TypeFactory method customComponent.

/**
	 * @deprecated Only for use temporary use by {@link org.hibernate.Hibernate}
	 */
@Deprecated
@SuppressWarnings({ "JavaDoc" })
public static CompositeCustomType customComponent(Class<CompositeUserType> typeClass, Properties parameters, TypeScope scope) {
    try {
        CompositeUserType userType = typeClass.newInstance();
        injectParameters(userType, parameters);
        return new CompositeCustomType(userType);
    } catch (Exception e) {
        throw new MappingException("Unable to instantiate custom type: " + typeClass.getName(), e);
    }
}
Also used : CompositeUserType(org.hibernate.usertype.CompositeUserType) MappingException(org.hibernate.MappingException) HibernateException(org.hibernate.HibernateException) MappingException(org.hibernate.MappingException)

Example 49 with MappingException

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

the class FetchProfileTest method testXmlOverride.

@Test
public void testXmlOverride() {
    Configuration config = new Configuration();
    config.addAnnotatedClass(Customer5.class);
    config.addAnnotatedClass(Order.class);
    config.addAnnotatedClass(Country.class);
    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml");
    config.addInputStream(is);
    SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) config.buildSessionFactory(serviceRegistry);
    assertTrue("fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition("orders-profile"));
    sessionImpl.close();
    // now the same with no xml
    final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer5.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
    try {
        metadataSources.buildMetadata();
        fail();
    } catch (MappingException e) {
        log.trace("success");
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) InputStream(java.io.InputStream) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) MappingException(org.hibernate.MappingException) Test(org.junit.Test)

Example 50 with MappingException

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

the class FetchProfileTest method testWrongAssociationName.

@Test
public void testWrongAssociationName() {
    final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer2.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
    try {
        metadataSources.buildMetadata();
        fail();
    } catch (MappingException e) {
        log.trace("success");
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) MappingException(org.hibernate.MappingException) Test(org.junit.Test)

Aggregations

MappingException (org.hibernate.MappingException)94 PersistentClass (org.hibernate.mapping.PersistentClass)17 HibernateException (org.hibernate.HibernateException)12 Iterator (java.util.Iterator)11 Test (org.junit.Test)11 AnnotationException (org.hibernate.AnnotationException)10 QueryException (org.hibernate.QueryException)10 Type (org.hibernate.type.Type)10 Property (org.hibernate.mapping.Property)9 HashMap (java.util.HashMap)8 XClass (org.hibernate.annotations.common.reflection.XClass)8 DuplicateMappingException (org.hibernate.DuplicateMappingException)6 Configuration (org.hibernate.cfg.Configuration)6 UnknownSqlResultSetMappingException (org.hibernate.procedure.UnknownSqlResultSetMappingException)6 ServiceRegistry (org.hibernate.service.ServiceRegistry)6 Map (java.util.Map)5 AssociationType (org.hibernate.type.AssociationType)5 HashSet (java.util.HashSet)4 ClassLoadingException (org.hibernate.annotations.common.reflection.ClassLoadingException)4 MetadataSources (org.hibernate.boot.MetadataSources)4