Search in sources :

Example 1 with ResultSetMappingDefinition

use of org.hibernate.engine.ResultSetMappingDefinition in project hibernate-orm by hibernate.

the class ResultSetMappingBinder method bind.

/**
	 * Build a ResultSetMappingDefinition given a containing element for the "return-XXX" elements
	 *
	 * @param resultSetMappingSource The XML data as a JAXB binding
	 * @param context The mapping state
	 * @param prefix A prefix to apply to named ResultSet mapping; this is either {@code null} for
	 * ResultSet mappings defined outside of any entity, or the name of the containing entity
	 * if defined within the context of an entity
	 *
	 * @return The ResultSet mapping descriptor
	 */
public static ResultSetMappingDefinition bind(ResultSetMappingBindingDefinition resultSetMappingSource, HbmLocalMetadataBuildingContext context, String prefix) {
    if (StringHelper.isEmpty(prefix)) {
        throw new AssertionFailure("Passed prefix was null; perhaps you meant to call the alternate #bind form?");
    }
    final String resultSetName = prefix + '.' + resultSetMappingSource.getName();
    final ResultSetMappingDefinition binding = new ResultSetMappingDefinition(resultSetName);
    bind(resultSetMappingSource, binding, context);
    return binding;
}
Also used : AssertionFailure(org.hibernate.AssertionFailure) ResultSetMappingDefinition(org.hibernate.engine.ResultSetMappingDefinition)

Example 2 with ResultSetMappingDefinition

use of org.hibernate.engine.ResultSetMappingDefinition in project hibernate-orm by hibernate.

the class ResultSetMappingBinder method bind.

/**
	 * Build a ResultSetMappingDefinition given a containing element for the "return-XXX" elements.
	 * <p/>
	 * This form is used for ResultSet mappings defined outside the context of any specific entity.
	 * For {@code hbm.xml} this means at the root of the document.  For annotations, this means at
	 * the package level.
	 *
	 * @param resultSetMappingSource The XML data as a JAXB binding
	 * @param context The mapping state
	 *
	 * @return The ResultSet mapping descriptor
	 */
public static ResultSetMappingDefinition bind(ResultSetMappingBindingDefinition resultSetMappingSource, HbmLocalMetadataBuildingContext context) {
    if (resultSetMappingSource.getName() == null) {
        throw new MappingException("ResultSet mapping did not specify name", context.getOrigin());
    }
    final ResultSetMappingDefinition binding = new ResultSetMappingDefinition(resultSetMappingSource.getName());
    bind(resultSetMappingSource, binding, context);
    return binding;
}
Also used : MappingException(org.hibernate.boot.MappingException) ResultSetMappingDefinition(org.hibernate.engine.ResultSetMappingDefinition)

Example 3 with ResultSetMappingDefinition

use of org.hibernate.engine.ResultSetMappingDefinition in project hibernate-orm by hibernate.

the class Configuration method reset.

protected void reset() {
    implicitNamingStrategy = ImplicitNamingStrategyJpaCompliantImpl.INSTANCE;
    physicalNamingStrategy = PhysicalNamingStrategyStandardImpl.INSTANCE;
    namedQueries = new HashMap<String, NamedQueryDefinition>();
    namedSqlQueries = new HashMap<String, NamedSQLQueryDefinition>();
    sqlResultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
    namedEntityGraphMap = new HashMap<String, NamedEntityGraphDefinition>();
    namedProcedureCallMap = new HashMap<String, NamedProcedureCallDefinition>();
    standardServiceRegistryBuilder = new StandardServiceRegistryBuilder(bootstrapServiceRegistry);
    entityTuplizerFactory = new EntityTuplizerFactory();
    interceptor = EmptyInterceptor.INSTANCE;
    properties = new Properties();
    properties.putAll(standardServiceRegistryBuilder.getSettings());
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) NamedQueryDefinition(org.hibernate.engine.spi.NamedQueryDefinition) Properties(java.util.Properties) NamedProcedureCallDefinition(org.hibernate.cfg.annotations.NamedProcedureCallDefinition) NamedEntityGraphDefinition(org.hibernate.cfg.annotations.NamedEntityGraphDefinition) NamedSQLQueryDefinition(org.hibernate.engine.spi.NamedSQLQueryDefinition) EntityTuplizerFactory(org.hibernate.tuple.entity.EntityTuplizerFactory) ResultSetMappingDefinition(org.hibernate.engine.ResultSetMappingDefinition)

Example 4 with ResultSetMappingDefinition

use of org.hibernate.engine.ResultSetMappingDefinition in project hibernate-orm by hibernate.

the class AbstractSharedSessionContract method resultClassChecking.

@SuppressWarnings({ "unchecked", "WeakerAccess" })
protected void resultClassChecking(Class resultType, NamedSQLQueryDefinition namedQueryDefinition) {
    final NativeSQLQueryReturn[] queryReturns;
    if (namedQueryDefinition.getQueryReturns() != null) {
        queryReturns = namedQueryDefinition.getQueryReturns();
    } else if (namedQueryDefinition.getResultSetRef() != null) {
        final ResultSetMappingDefinition rsMapping = getFactory().getNamedQueryRepository().getResultSetMappingDefinition(namedQueryDefinition.getResultSetRef());
        queryReturns = rsMapping.getQueryReturns();
    } else {
        throw new AssertionFailure("Unsupported named query model. Please report the bug in Hibernate EntityManager");
    }
    if (queryReturns.length > 1) {
        throw new IllegalArgumentException("Cannot create TypedQuery for query with more than one return");
    }
    final NativeSQLQueryReturn nativeSQLQueryReturn = queryReturns[0];
    if (nativeSQLQueryReturn instanceof NativeSQLQueryRootReturn) {
        final Class<?> actualReturnedClass;
        final String entityClassName = ((NativeSQLQueryRootReturn) nativeSQLQueryReturn).getReturnEntityName();
        try {
            actualReturnedClass = getFactory().getServiceRegistry().getService(ClassLoaderService.class).classForName(entityClassName);
        } catch (ClassLoadingException e) {
            throw new AssertionFailure("Unable to load class [" + entityClassName + "] declared on named native query [" + namedQueryDefinition.getName() + "]");
        }
        if (!resultType.isAssignableFrom(actualReturnedClass)) {
            throw buildIncompatibleException(resultType, actualReturnedClass);
        }
    } else if (nativeSQLQueryReturn instanceof NativeSQLQueryConstructorReturn) {
        final NativeSQLQueryConstructorReturn ctorRtn = (NativeSQLQueryConstructorReturn) nativeSQLQueryReturn;
        if (!resultType.isAssignableFrom(ctorRtn.getTargetClass())) {
            throw buildIncompatibleException(resultType, ctorRtn.getTargetClass());
        }
    } else {
        log.debugf("Skiping unhandled NativeSQLQueryReturn type : " + nativeSQLQueryReturn);
    }
}
Also used : AssertionFailure(org.hibernate.AssertionFailure) NativeSQLQueryConstructorReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryConstructorReturn) NativeSQLQueryReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) NativeSQLQueryRootReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn) ResultSetMappingDefinition(org.hibernate.engine.ResultSetMappingDefinition)

Example 5 with ResultSetMappingDefinition

use of org.hibernate.engine.ResultSetMappingDefinition in project hibernate-orm by hibernate.

the class Util method resolveResultSetMappings.

/**
	 * Resolve the given result set mapping names
	 *
	 * @param context The context for the resolution.  See {@link ResultSetMappingResolutionContext}
	 * @param resultSetMappingNames The names of the result-set-mappings to resolve
	 */
public static void resolveResultSetMappings(ResultSetMappingResolutionContext context, String... resultSetMappingNames) {
    for (String resultSetMappingName : resultSetMappingNames) {
        log.tracef("Starting attempt resolve named result-set-mapping : %s", resultSetMappingName);
        final ResultSetMappingDefinition mapping = context.findResultSetMapping(resultSetMappingName);
        if (mapping == null) {
            throw new UnknownSqlResultSetMappingException("Unknown SqlResultSetMapping [" + resultSetMappingName + "]");
        }
        log.tracef("Found result-set-mapping : %s", mapping.traceLoggableFormat());
        context.addQueryReturns(mapping.getQueryReturns());
        final SQLQueryReturnProcessor processor = new SQLQueryReturnProcessor(mapping.getQueryReturns(), context.getSessionFactory());
        final SQLQueryReturnProcessor.ResultAliasContext processResult = processor.process();
        context.addQuerySpaces(processResult.collectQuerySpaces());
    }
}
Also used : UnknownSqlResultSetMappingException(org.hibernate.procedure.UnknownSqlResultSetMappingException) SQLQueryReturnProcessor(org.hibernate.loader.custom.sql.SQLQueryReturnProcessor) ResultSetMappingDefinition(org.hibernate.engine.ResultSetMappingDefinition)

Aggregations

ResultSetMappingDefinition (org.hibernate.engine.ResultSetMappingDefinition)10 MappingException (org.hibernate.MappingException)4 HashMap (java.util.HashMap)3 NamedSQLQueryDefinition (org.hibernate.engine.spi.NamedSQLQueryDefinition)3 Map (java.util.Map)2 AssertionFailure (org.hibernate.AssertionFailure)2 NativeSQLQueryConstructorReturn (org.hibernate.engine.query.spi.sql.NativeSQLQueryConstructorReturn)2 NativeSQLQueryReturn (org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn)2 NativeSQLQueryRootReturn (org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn)2 NamedQueryDefinition (org.hibernate.engine.spi.NamedQueryDefinition)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 ColumnResult (javax.persistence.ColumnResult)1 ConstructorResult (javax.persistence.ConstructorResult)1 EntityResult (javax.persistence.EntityResult)1 FieldResult (javax.persistence.FieldResult)1 HibernateException (org.hibernate.HibernateException)1 MappingException (org.hibernate.boot.MappingException)1