Search in sources :

Example 16 with MappingException

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

the class FetchProfileTest method testWrongClass.

@Test
public void testWrongClass() {
    final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer3.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)

Example 17 with MappingException

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

the class FetchProfileTest method testUnsupportedFetchMode.

@Test
public void testUnsupportedFetchMode() {
    final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer4.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)

Example 18 with MappingException

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

the class PersistentClassTest method testGetProperty.

@Test
public void testGetProperty() {
    RootClass pc = new RootClass(metadataBuildingContext);
    Property p = new Property();
    p.setName("name");
    pc.addProperty(p);
    Assert.assertEquals(p, pc.getProperty("name"));
    Assert.assertEquals(p, pc.getProperty("name.test"));
    try {
        Assert.assertNull(pc.getProperty("test"));
        Assert.fail("MappingException expected");
    } catch (MappingException e) {
    // expected
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass) Property(org.hibernate.mapping.Property) MappingException(org.hibernate.MappingException) Test(org.junit.Test)

Example 19 with MappingException

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

the class PathExpressionParser method token.

public void token(String token, QueryTranslatorImpl q) throws QueryException {
    if (token != null) {
        path.append(token);
    }
    String alias = q.getPathAlias(path.toString());
    if (alias != null) {
        //reset the dotcount (but not the path)
        reset(q);
        //afterQuery reset!
        currentName = alias;
        currentPropertyMapping = q.getPropertyMapping(currentName);
        if (!ignoreInitialJoin) {
            JoinSequence ojf = q.getPathJoin(path.toString());
            try {
                //afterQuery reset!
                joinSequence.addCondition(ojf.toJoinFragment(q.getEnabledFilters(), true).toWhereFragmentString());
            } catch (MappingException me) {
                throw new QueryException(me);
            }
        // we don't need to worry about any condition in the ON clause
        // here (toFromFragmentString), since anything in the ON condition
        // is already applied to the whole query
        }
    } else if (".".equals(token)) {
        dotcount++;
    } else {
        if (dotcount == 0) {
            if (!continuation) {
                if (!q.isName(token)) {
                    throw new QueryException("undefined alias: " + token);
                }
                currentName = token;
                currentPropertyMapping = q.getPropertyMapping(currentName);
            }
        } else if (dotcount == 1) {
            if (currentName != null) {
                currentProperty = token;
            } else if (collectionName != null) {
                //processCollectionProperty(token, q.getCollectionPersister(collectionRole), collectionName);
                continuation = false;
            } else {
                throw new QueryException("unexpected");
            }
        } else {
            // dotcount>=2
            // Do the corresponding RHS
            Type propertyType = getPropertyType();
            if (propertyType == null) {
                throw new QueryException("unresolved property: " + path);
            }
            if (propertyType.isComponentType()) {
                dereferenceComponent(token);
            } else if (propertyType.isEntityType()) {
                if (!isCollectionValued()) {
                    dereferenceEntity(token, (EntityType) propertyType, q);
                }
            } else if (propertyType.isCollectionType()) {
                dereferenceCollection(token, ((CollectionType) propertyType).getRole(), q);
            } else {
                if (token != null) {
                    throw new QueryException("dereferenced: " + path);
                }
            }
        }
    }
}
Also used : EntityType(org.hibernate.type.EntityType) QueryException(org.hibernate.QueryException) JoinType(org.hibernate.sql.JoinType) CollectionType(org.hibernate.type.CollectionType) EntityType(org.hibernate.type.EntityType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) JoinSequence(org.hibernate.engine.internal.JoinSequence) MappingException(org.hibernate.MappingException)

Example 20 with MappingException

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

the class QueryTranslatorImpl method compile.

/**
	 * Compile the query (generate the SQL).
	 *
	 * @throws org.hibernate.MappingException Indicates problems resolving
	 * things referenced in the query.
	 * @throws org.hibernate.QueryException Generally some form of syntatic
	 * failure.
	 */
private void compile() throws QueryException, MappingException {
    LOG.trace("Compiling query");
    try {
        ParserHelper.parse(new PreprocessingParser(tokenReplacements), queryString, ParserHelper.HQL_SEPARATORS, this);
        renderSQL();
    } catch (QueryException qe) {
        if (qe.getQueryString() == null) {
            throw qe.wrapWithQueryString(queryString);
        } else {
            throw qe;
        }
    } catch (MappingException me) {
        throw me;
    } catch (Exception e) {
        LOG.debug("Unexpected query compilation problem", e);
        e.printStackTrace();
        throw new QueryException("Incorrect query syntax", queryString, e);
    }
    postInstantiate();
    compiled = true;
}
Also used : QueryException(org.hibernate.QueryException) MappingException(org.hibernate.MappingException) HibernateException(org.hibernate.HibernateException) QueryException(org.hibernate.QueryException) SQLException(java.sql.SQLException) MappingException(org.hibernate.MappingException)

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