All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.annotations.SQLSelect Maven / Gradle / Ivy

There is a newer version: 6.6.2.Final
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.annotations;

import jakarta.persistence.SqlResultSetMapping;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * Specifies a custom SQL query to be used in place of the default SQL
 * generated by Hibernate when an entity or collection is loaded from the
 * database by id. This occurs when:
 * 
    *
  • an association to an entity is fetched lazily, *
  • a collection is fetched lazily, or *
  • when an entity is retrieved using {@link org.hibernate.Session#get} * or {@link org.hibernate.Session#find}. *
*

* The given {@linkplain #sql SQL statement} must have exactly the number * of JDBC {@code ?} parameters that Hibernate expects, that is, one for * each column of: *

    *
  1. the {@linkplain jakarta.persistence.Id primary key}, in the case of * an entity, or *
  2. the foreign key, in the case of a collection. *
*

* Optionally, an explicit {@linkplain #resultSetMapping result set mapping} * may be specified. It should have: *

    *
  1. a single {@link jakarta.persistence.EntityResult}, if the SQL query * loads an {@linkplain jakarta.persistence.Entity entity}, * {@linkplain jakarta.persistence.OneToMany one-to-many} association, * or {@linkplain jakarta.persistence.ManyToMany many-to-many} association, * or *
  2. a single {@link jakarta.persistence.ColumnResult} or * {@link jakarta.persistence.ConstructorResult}, if the SQL query * loads an {@linkplain jakarta.persistence.ElementCollection collection} * of basic-typed values. *
* * @see HQLSelect * @see DialectOverride.SQLSelect * * @author Gavin King * * @since 6.2 * * @implNote This annotation is just an abbreviation for {@link Loader} * together with {@link NamedNativeQuery}. */ @Target({TYPE, FIELD, METHOD}) @Retention(RUNTIME) public @interface SQLSelect { /** * The SQL {@code SELECT} statement. */ String sql(); /** * A {@link SqlResultSetMapping} with a single * {@link jakarta.persistence.ColumnResult} or * {@link jakarta.persistence.EntityResult}. */ SqlResultSetMapping resultSetMapping() default @SqlResultSetMapping(name=""); /** * The query spaces involved in this query. * * @see org.hibernate.query.SynchronizeableQuery */ String[] querySpaces() default {}; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy