HHH-18192 remove @Loader
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
cc272f704e
commit
5d91c89057
|
@ -36,9 +36,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
*
|
*
|
||||||
* @since 6.2
|
* @since 6.2
|
||||||
*
|
|
||||||
* @implNote This annotation is just an abbreviation for {@link Loader}
|
|
||||||
* together with {@link NamedQuery}.
|
|
||||||
*/
|
*/
|
||||||
@Target({TYPE, FIELD, METHOD})
|
@Target({TYPE, FIELD, METHOD})
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
*/
|
|
||||||
package org.hibernate.annotations;
|
|
||||||
|
|
||||||
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 that a named query should be used to load an entity or
|
|
||||||
* collection, overriding the SQL that Hibernate generates by default.
|
|
||||||
*
|
|
||||||
* @author László Benke
|
|
||||||
*
|
|
||||||
* @deprecated Use {@link SQLSelect} or {@link HQLSelect}.
|
|
||||||
*/
|
|
||||||
@Target( {TYPE, FIELD, METHOD} )
|
|
||||||
@Retention( RUNTIME )
|
|
||||||
@Deprecated(since = "6.2")
|
|
||||||
public @interface Loader {
|
|
||||||
/**
|
|
||||||
* The named query to use for loading the entity or collection.
|
|
||||||
*/
|
|
||||||
String namedQuery() default "";
|
|
||||||
}
|
|
|
@ -56,9 +56,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
*
|
*
|
||||||
* @since 6.2
|
* @since 6.2
|
||||||
*
|
|
||||||
* @implNote This annotation is just an abbreviation for {@link Loader}
|
|
||||||
* together with {@link NamedNativeQuery}.
|
|
||||||
*/
|
*/
|
||||||
@Target({TYPE, FIELD, METHOD})
|
@Target({TYPE, FIELD, METHOD})
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
|
|
|
@ -46,7 +46,6 @@ import org.hibernate.annotations.ListIndexBase;
|
||||||
import org.hibernate.annotations.ListIndexJavaType;
|
import org.hibernate.annotations.ListIndexJavaType;
|
||||||
import org.hibernate.annotations.ListIndexJdbcType;
|
import org.hibernate.annotations.ListIndexJdbcType;
|
||||||
import org.hibernate.annotations.ListIndexJdbcTypeCode;
|
import org.hibernate.annotations.ListIndexJdbcTypeCode;
|
||||||
import org.hibernate.annotations.Loader;
|
|
||||||
import org.hibernate.annotations.ManyToAny;
|
import org.hibernate.annotations.ManyToAny;
|
||||||
import org.hibernate.annotations.MapKeyJavaType;
|
import org.hibernate.annotations.MapKeyJavaType;
|
||||||
import org.hibernate.annotations.MapKeyJdbcType;
|
import org.hibernate.annotations.MapKeyJdbcType;
|
||||||
|
@ -1414,11 +1413,6 @@ public abstract class CollectionBinder {
|
||||||
collection.setLoaderName( loaderName );
|
collection.setLoaderName( loaderName );
|
||||||
QueryBinder.bindQuery( loaderName, hqlSelect, buildingContext );
|
QueryBinder.bindQuery( loaderName, hqlSelect, buildingContext );
|
||||||
}
|
}
|
||||||
|
|
||||||
final Loader loader = property.getDirectAnnotationUsage( Loader.class );
|
|
||||||
if ( loader != null ) {
|
|
||||||
collection.setLoaderName( loader.namedQuery() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applySortingAndOrdering() {
|
private void applySortingAndOrdering() {
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.hibernate.annotations.Filter;
|
||||||
import org.hibernate.annotations.Filters;
|
import org.hibernate.annotations.Filters;
|
||||||
import org.hibernate.annotations.HQLSelect;
|
import org.hibernate.annotations.HQLSelect;
|
||||||
import org.hibernate.annotations.Immutable;
|
import org.hibernate.annotations.Immutable;
|
||||||
import org.hibernate.annotations.Loader;
|
|
||||||
import org.hibernate.annotations.Mutability;
|
import org.hibernate.annotations.Mutability;
|
||||||
import org.hibernate.annotations.NaturalIdCache;
|
import org.hibernate.annotations.NaturalIdCache;
|
||||||
import org.hibernate.annotations.OnDelete;
|
import org.hibernate.annotations.OnDelete;
|
||||||
|
@ -1348,8 +1347,6 @@ public class EntityBinder {
|
||||||
|
|
||||||
ensureNoMutabilityPlan();
|
ensureNoMutabilityPlan();
|
||||||
|
|
||||||
bindCustomLoader();
|
|
||||||
|
|
||||||
registerImportName();
|
registerImportName();
|
||||||
|
|
||||||
processNamedEntityGraphs();
|
processNamedEntityGraphs();
|
||||||
|
@ -1466,13 +1463,6 @@ public class EntityBinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindCustomLoader() {
|
|
||||||
final Loader loader = annotatedClass.getAnnotationUsage( Loader.class, getSourceModelContext() );
|
|
||||||
if ( loader != null ) {
|
|
||||||
persistentClass.setLoaderName( loader.namedQuery() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bindSubselect() {
|
private void bindSubselect() {
|
||||||
final Subselect subselect = annotatedClass.getAnnotationUsage( Subselect.class, getSourceModelContext() );
|
final Subselect subselect = annotatedClass.getAnnotationUsage( Subselect.class, getSourceModelContext() );
|
||||||
if ( subselect != null ) {
|
if ( subselect != null ) {
|
||||||
|
|
|
@ -402,10 +402,6 @@ public interface HibernateAnnotations {
|
||||||
ListIndexJdbcTypeCode.class,
|
ListIndexJdbcTypeCode.class,
|
||||||
ListIndexJdbcTypeCodeAnnotation.class
|
ListIndexJdbcTypeCodeAnnotation.class
|
||||||
);
|
);
|
||||||
OrmAnnotationDescriptor<Loader, LoaderAnnotation> LOADER = new OrmAnnotationDescriptor<>(
|
|
||||||
Loader.class,
|
|
||||||
LoaderAnnotation.class
|
|
||||||
);
|
|
||||||
OrmAnnotationDescriptor<ManyToAny, ManyToAnyAnnotation> MANY_TO_ANY = new OrmAnnotationDescriptor<>(
|
OrmAnnotationDescriptor<ManyToAny, ManyToAnyAnnotation> MANY_TO_ANY = new OrmAnnotationDescriptor<>(
|
||||||
ManyToAny.class,
|
ManyToAny.class,
|
||||||
ManyToAnyAnnotation.class
|
ManyToAnyAnnotation.class
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 http://www.gnu.org/licenses/lgpl-2.1.html.
|
|
||||||
*/
|
|
||||||
package org.hibernate.boot.models.annotations.internal;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
|
|
||||||
import org.hibernate.annotations.Loader;
|
|
||||||
import org.hibernate.boot.models.HibernateAnnotations;
|
|
||||||
import org.hibernate.models.spi.SourceModelBuildingContext;
|
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
|
||||||
|
|
||||||
import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue;
|
|
||||||
|
|
||||||
@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" })
|
|
||||||
@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor")
|
|
||||||
public class LoaderAnnotation implements Loader {
|
|
||||||
private String namedQuery;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used in creating dynamic annotation instances (e.g. from XML)
|
|
||||||
*/
|
|
||||||
public LoaderAnnotation(SourceModelBuildingContext modelContext) {
|
|
||||||
this.namedQuery = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used in creating annotation instances from JDK variant
|
|
||||||
*/
|
|
||||||
public LoaderAnnotation(Loader annotation, SourceModelBuildingContext modelContext) {
|
|
||||||
this.namedQuery = annotation.namedQuery();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used in creating annotation instances from Jandex variant
|
|
||||||
*/
|
|
||||||
public LoaderAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) {
|
|
||||||
this.namedQuery = extractJandexValue( annotation, HibernateAnnotations.LOADER, "namedQuery", modelContext );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<? extends Annotation> annotationType() {
|
|
||||||
return Loader.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String namedQuery() {
|
|
||||||
return namedQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void namedQuery(String value) {
|
|
||||||
this.namedQuery = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -24,12 +24,6 @@ import org.junit.Test;
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class LoaderTest extends BaseCoreFunctionalTestCase {
|
public class LoaderTest extends BaseCoreFunctionalTestCase {
|
||||||
@Override
|
|
||||||
protected String[] getOrmXmlFiles() {
|
|
||||||
return new String[] {
|
|
||||||
"org/hibernate/orm/test/annotations/loader/Loader.hbm.xml"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.annotations.Loader;
|
import org.hibernate.annotations.HQLSelect;
|
||||||
import org.hibernate.annotations.NamedQuery;
|
import org.hibernate.annotations.NamedQuery;
|
||||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ public class LoaderWithInvalidQueryTest extends BaseEntityManagerFunctionalTestC
|
||||||
HibernateException rootCause = (HibernateException) ExceptionUtil.rootCause( expected );
|
HibernateException rootCause = (HibernateException) ExceptionUtil.rootCause( expected );
|
||||||
Throwable[] suppressed = rootCause.getSuppressed();
|
Throwable[] suppressed = rootCause.getSuppressed();
|
||||||
assertEquals( 2, suppressed.length );
|
assertEquals( 2, suppressed.length );
|
||||||
assertTrue( ExceptionUtil.rootCause( suppressed[0] ).getMessage().contains( "Could not resolve attribute 'valid'" ) );
|
assertTrue( ExceptionUtil.rootCause( suppressed[0] ).getMessage().contains( "Could not resolve root entity '_Person'" ) );
|
||||||
assertTrue( ExceptionUtil.rootCause( suppressed[1] ).getMessage().contains( "Could not resolve root entity '_Person'" ) );
|
assertTrue( ExceptionUtil.rootCause( suppressed[1] ).getMessage().contains( "Could not resolve attribute 'valid'" ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,9 +54,7 @@ public class LoaderWithInvalidQueryTest extends BaseEntityManagerFunctionalTestC
|
||||||
|
|
||||||
|
|
||||||
@Entity(name = "Person")
|
@Entity(name = "Person")
|
||||||
@Loader(namedQuery = "invalid_sql")
|
@HQLSelect(
|
||||||
@NamedQuery(
|
|
||||||
name = "invalid_sql",
|
|
||||||
query = "SELECT p " +
|
query = "SELECT p " +
|
||||||
"FROM Person p " +
|
"FROM Person p " +
|
||||||
"WHERE p.id = ?1 and p.valid = true"
|
"WHERE p.id = ?1 and p.valid = true"
|
||||||
|
|
|
@ -8,14 +8,16 @@ package org.hibernate.orm.test.annotations.loader;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EntityResult;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
|
|
||||||
|
import jakarta.persistence.SqlResultSetMapping;
|
||||||
import org.hibernate.annotations.Fetch;
|
import org.hibernate.annotations.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
import org.hibernate.annotations.Loader;
|
import org.hibernate.annotations.SQLSelect;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Team {
|
public class Team {
|
||||||
|
@ -34,7 +36,9 @@ public class Team {
|
||||||
|
|
||||||
@OneToMany(targetEntity = Player.class, mappedBy = "team", fetch = FetchType.EAGER)
|
@OneToMany(targetEntity = Player.class, mappedBy = "team", fetch = FetchType.EAGER)
|
||||||
@Fetch(FetchMode.SELECT)
|
@Fetch(FetchMode.SELECT)
|
||||||
@Loader(namedQuery = "loadByTeam")
|
@SQLSelect(sql = "select * from Player where team_id = ?1",
|
||||||
|
resultSetMapping = @SqlResultSetMapping(name = "",
|
||||||
|
entities = @EntityResult(entityClass = Player.class)))
|
||||||
public Set<Player> getPlayers() {
|
public Set<Player> getPlayers() {
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,13 @@ import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.NamedNativeQuery;
|
|
||||||
import jakarta.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.annotations.Loader;
|
|
||||||
import org.hibernate.annotations.SQLDelete;
|
import org.hibernate.annotations.SQLDelete;
|
||||||
import org.hibernate.annotations.SQLDeleteAll;
|
import org.hibernate.annotations.SQLDeleteAll;
|
||||||
import org.hibernate.annotations.SQLInsert;
|
import org.hibernate.annotations.SQLInsert;
|
||||||
|
import org.hibernate.annotations.SQLSelect;
|
||||||
import org.hibernate.annotations.SQLUpdate;
|
import org.hibernate.annotations.SQLUpdate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,8 +30,7 @@ import org.hibernate.annotations.SQLUpdate;
|
||||||
@SQLInsert( sql="INSERT INTO CHAOS(name, nick_name, chaos_size, id) VALUES(upper(?),?,?,?)")
|
@SQLInsert( sql="INSERT INTO CHAOS(name, nick_name, chaos_size, id) VALUES(upper(?),?,?,?)")
|
||||||
@SQLUpdate( sql="UPDATE CHAOS SET name = upper(?), nick_name = ?, chaos_size = ? WHERE id = ?")
|
@SQLUpdate( sql="UPDATE CHAOS SET name = upper(?), nick_name = ?, chaos_size = ? WHERE id = ?")
|
||||||
@SQLDelete( sql="DELETE CHAOS WHERE id = ?")
|
@SQLDelete( sql="DELETE CHAOS WHERE id = ?")
|
||||||
@Loader(namedQuery = "chaos")
|
@SQLSelect( sql="select id, chaos_size, name, lower( nick_name ) as nick_name from CHAOS where id= ?" )
|
||||||
@NamedNativeQuery(name="chaos", query="select id, chaos_size, name, lower( nick_name ) as nick_name from CHAOS where id= ?", resultClass = Chaos.class)
|
|
||||||
public class Chaos {
|
public class Chaos {
|
||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
|
@ -6,11 +6,10 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.persister.entity;
|
package org.hibernate.orm.test.persister.entity;
|
||||||
|
|
||||||
import org.hibernate.annotations.Loader;
|
|
||||||
import org.hibernate.annotations.NamedNativeQuery;
|
|
||||||
import org.hibernate.annotations.ResultCheckStyle;
|
import org.hibernate.annotations.ResultCheckStyle;
|
||||||
import org.hibernate.annotations.SQLDelete;
|
import org.hibernate.annotations.SQLDelete;
|
||||||
import org.hibernate.annotations.SQLInsert;
|
import org.hibernate.annotations.SQLInsert;
|
||||||
|
import org.hibernate.annotations.SQLSelect;
|
||||||
import org.hibernate.annotations.SQLUpdate;
|
import org.hibernate.annotations.SQLUpdate;
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
import org.hibernate.persister.entity.AbstractEntityPersister;
|
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||||
|
@ -87,12 +86,7 @@ public class CustomSqlSchemaResolvingIdentityTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "CardWithCustomSQL")
|
@Entity(name = "CardWithCustomSQL")
|
||||||
@Loader(namedQuery = "find_foo_by_id")
|
@SQLSelect(sql = "SELECT id, name FROM {h-schema}FOO WHERE id = ?")
|
||||||
@NamedNativeQuery(
|
|
||||||
name = "find_foo_by_id",
|
|
||||||
query = "SELECT id, name FROM {h-schema}FOO WHERE id = ?",
|
|
||||||
resultClass = CustomEntity.class
|
|
||||||
)
|
|
||||||
@SQLInsert(sql = "INSERT INTO {h-schema}FOO (name) VALUES (?)")
|
@SQLInsert(sql = "INSERT INTO {h-schema}FOO (name) VALUES (?)")
|
||||||
@SQLDelete(sql = "DELETE FROM {h-schema}FOO WHERE id = ?", check = ResultCheckStyle.COUNT)
|
@SQLDelete(sql = "DELETE FROM {h-schema}FOO WHERE id = ?", check = ResultCheckStyle.COUNT)
|
||||||
@SQLUpdate(sql = "UPDATE {h-schema}FOO SET name = ? WHERE id = ? ")
|
@SQLUpdate(sql = "UPDATE {h-schema}FOO SET name = ? WHERE id = ? ")
|
||||||
|
|
|
@ -6,11 +6,10 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.persister.entity;
|
package org.hibernate.orm.test.persister.entity;
|
||||||
|
|
||||||
import org.hibernate.annotations.Loader;
|
|
||||||
import org.hibernate.annotations.NamedNativeQuery;
|
|
||||||
import org.hibernate.annotations.ResultCheckStyle;
|
import org.hibernate.annotations.ResultCheckStyle;
|
||||||
import org.hibernate.annotations.SQLDelete;
|
import org.hibernate.annotations.SQLDelete;
|
||||||
import org.hibernate.annotations.SQLInsert;
|
import org.hibernate.annotations.SQLInsert;
|
||||||
|
import org.hibernate.annotations.SQLSelect;
|
||||||
import org.hibernate.annotations.SQLUpdate;
|
import org.hibernate.annotations.SQLUpdate;
|
||||||
import org.hibernate.persister.entity.AbstractEntityPersister;
|
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||||
import org.hibernate.sql.model.jdbc.JdbcMutationOperation;
|
import org.hibernate.sql.model.jdbc.JdbcMutationOperation;
|
||||||
|
@ -81,12 +80,7 @@ public class CustomSqlSchemaResolvingTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "CardWithCustomSQL")
|
@Entity(name = "CardWithCustomSQL")
|
||||||
@Loader(namedQuery = "find_foo_by_id")
|
@SQLSelect(sql = "SELECT id, name FROM {h-schema}FOO WHERE id = ?")
|
||||||
@NamedNativeQuery(
|
|
||||||
name = "find_foo_by_id",
|
|
||||||
query = "SELECT id, name FROM {h-schema}FOO WHERE id = ?",
|
|
||||||
resultClass = CustomEntity.class
|
|
||||||
)
|
|
||||||
@SQLInsert(sql = "INSERT INTO {h-schema}FOO (name, id) VALUES (?, ?)")
|
@SQLInsert(sql = "INSERT INTO {h-schema}FOO (name, id) VALUES (?, ?)")
|
||||||
@SQLDelete(sql = "DELETE FROM {h-schema}FOO WHERE id = ?", check = ResultCheckStyle.COUNT)
|
@SQLDelete(sql = "DELETE FROM {h-schema}FOO WHERE id = ?", check = ResultCheckStyle.COUNT)
|
||||||
@SQLUpdate(sql = "UPDATE {h-schema}FOO SET name = ? WHERE id = ? ")
|
@SQLUpdate(sql = "UPDATE {h-schema}FOO SET name = ? WHERE id = ? ")
|
||||||
|
|
|
@ -16,12 +16,11 @@ import jakarta.persistence.ElementCollection;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.NamedNativeQuery;
|
|
||||||
|
|
||||||
import org.hibernate.annotations.Loader;
|
|
||||||
import org.hibernate.annotations.SQLDelete;
|
import org.hibernate.annotations.SQLDelete;
|
||||||
import org.hibernate.annotations.SQLDeleteAll;
|
import org.hibernate.annotations.SQLDeleteAll;
|
||||||
import org.hibernate.annotations.SQLInsert;
|
import org.hibernate.annotations.SQLInsert;
|
||||||
|
import org.hibernate.annotations.SQLSelect;
|
||||||
import org.hibernate.annotations.SQLUpdate;
|
import org.hibernate.annotations.SQLUpdate;
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
|
@ -114,20 +113,7 @@ public class CollectionLoaderTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
@SQLInsert(sql = "INSERT INTO person (name, id, valid) VALUES (?, ?, true) ", check = COUNT)
|
@SQLInsert(sql = "INSERT INTO person (name, id, valid) VALUES (?, ?, true) ", check = COUNT)
|
||||||
@SQLUpdate(sql = "UPDATE person SET name = ? where id = ? ")
|
@SQLUpdate(sql = "UPDATE person SET name = ? where id = ? ")
|
||||||
@SQLDelete(sql = "UPDATE person SET valid = false WHERE id = ? ")
|
@SQLDelete(sql = "UPDATE person SET valid = false WHERE id = ? ")
|
||||||
@Loader(namedQuery = "find_valid_person")
|
@SQLSelect(sql = "SELECT id, name FROM person WHERE id = ? and valid = true")
|
||||||
@NamedNativeQuery(
|
|
||||||
name = "find_valid_person",
|
|
||||||
query = "SELECT id, name " +
|
|
||||||
"FROM person " +
|
|
||||||
"WHERE id = ? and valid = true",
|
|
||||||
resultClass = Person.class
|
|
||||||
)
|
|
||||||
@NamedNativeQuery(
|
|
||||||
name = "find_valid_phones",
|
|
||||||
query = "SELECT phones " +
|
|
||||||
"FROM Person_phones " +
|
|
||||||
"WHERE person_id = ? and valid = true "
|
|
||||||
)
|
|
||||||
public static class Person {
|
public static class Person {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -139,7 +125,7 @@ public class CollectionLoaderTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
@ElementCollection
|
@ElementCollection
|
||||||
@SQLInsert(sql = "INSERT INTO person_phones (person_id, phones, valid) VALUES (?, ?, true) ")
|
@SQLInsert(sql = "INSERT INTO person_phones (person_id, phones, valid) VALUES (?, ?, true) ")
|
||||||
@SQLDeleteAll(sql = "UPDATE person_phones SET valid = false WHERE person_id = ?")
|
@SQLDeleteAll(sql = "UPDATE person_phones SET valid = false WHERE person_id = ?")
|
||||||
@Loader(namedQuery = "find_valid_phones")
|
@SQLSelect(sql = "SELECT phones FROM Person_phones WHERE person_id = ? and valid = true")
|
||||||
private List<String> phones = new ArrayList<>();
|
private List<String> phones = new ArrayList<>();
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
|
|
|
@ -11,17 +11,15 @@ import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.NamedNativeQueries;
|
|
||||||
import jakarta.persistence.NamedNativeQuery;
|
|
||||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||||
import jakarta.persistence.SecondaryTable;
|
import jakarta.persistence.SecondaryTable;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.annotations.Loader;
|
|
||||||
import org.hibernate.annotations.ResultCheckStyle;
|
import org.hibernate.annotations.ResultCheckStyle;
|
||||||
import org.hibernate.annotations.SQLDelete;
|
import org.hibernate.annotations.SQLDelete;
|
||||||
import org.hibernate.annotations.SQLInsert;
|
import org.hibernate.annotations.SQLInsert;
|
||||||
|
import org.hibernate.annotations.SQLSelect;
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||||
|
@ -108,20 +106,15 @@ public class CustomSQLSecondaryTableTest extends BaseEntityManagerFunctionalTest
|
||||||
sql = "UPDATE person_details SET valid = false WHERE person_id = ? "
|
sql = "UPDATE person_details SET valid = false WHERE person_id = ? "
|
||||||
)
|
)
|
||||||
|
|
||||||
@Loader(namedQuery = "find_valid_person")
|
@SQLSelect(
|
||||||
@NamedNativeQueries({
|
sql = "SELECT " +
|
||||||
@NamedNativeQuery(
|
" p.id, " +
|
||||||
name = "find_valid_person",
|
" p.name, " +
|
||||||
query = "SELECT " +
|
" pd.image " +
|
||||||
" p.id, " +
|
"FROM person p " +
|
||||||
" p.name, " +
|
"LEFT OUTER JOIN person_details pd ON p.id = pd.person_id " +
|
||||||
" pd.image " +
|
"WHERE p.id = ? AND p.valid = true AND pd.valid = true"
|
||||||
"FROM person p " +
|
)
|
||||||
"LEFT OUTER JOIN person_details pd ON p.id = pd.person_id " +
|
|
||||||
"WHERE p.id = ? AND p.valid = true AND pd.valid = true",
|
|
||||||
resultClass = Person.class
|
|
||||||
)
|
|
||||||
})
|
|
||||||
public static class Person {
|
public static class Person {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|
|
@ -9,10 +9,10 @@ package org.hibernate.orm.test.sql;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.annotations.Loader;
|
|
||||||
import org.hibernate.annotations.ResultCheckStyle;
|
import org.hibernate.annotations.ResultCheckStyle;
|
||||||
import org.hibernate.annotations.SQLDelete;
|
import org.hibernate.annotations.SQLDelete;
|
||||||
import org.hibernate.annotations.SQLInsert;
|
import org.hibernate.annotations.SQLInsert;
|
||||||
|
import org.hibernate.annotations.SQLSelect;
|
||||||
import org.hibernate.dialect.OracleDialect;
|
import org.hibernate.dialect.OracleDialect;
|
||||||
|
|
||||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||||
|
@ -24,8 +24,6 @@ import org.junit.jupiter.api.Test;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.NamedNativeQueries;
|
|
||||||
import jakarta.persistence.NamedNativeQuery;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
@ -98,16 +96,7 @@ public class OracleCustomSQLWithStoredProcedureTest {
|
||||||
callable = true
|
callable = true
|
||||||
)
|
)
|
||||||
//end::sql-sp-custom-crud-example[]
|
//end::sql-sp-custom-crud-example[]
|
||||||
@Loader(namedQuery = "find_valid_person")
|
@SQLSelect(sql = "SELECT id, name FROM person WHERE id = ? and valid = 1")
|
||||||
@NamedNativeQueries({
|
|
||||||
@NamedNativeQuery(
|
|
||||||
name = "find_valid_person",
|
|
||||||
query = "SELECT id, name " +
|
|
||||||
"FROM person " +
|
|
||||||
"WHERE id = ? and valid = 1",
|
|
||||||
resultClass = Person.class
|
|
||||||
)
|
|
||||||
})
|
|
||||||
public static class Person {
|
public static class Person {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<!--
|
|
||||||
~ 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
|
||||||
-->
|
|
||||||
<!DOCTYPE hibernate-mapping PUBLIC
|
|
||||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
|
||||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
|
|
||||||
Used to demonstrate the declarative configuration
|
|
||||||
of both hbm files and annotated classes
|
|
||||||
See hibernate.cfg.xml and ConfigurationTest
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<hibernate-mapping package="org.hibernate.orm.test.annotations.loader">
|
|
||||||
|
|
||||||
<sql-query name="loadByTeam">
|
|
||||||
<load-collection alias="p" role="Team.players"/>
|
|
||||||
select {p.*} from Player p where p.team_id = ?1
|
|
||||||
</sql-query>
|
|
||||||
|
|
||||||
</hibernate-mapping>
|
|
Loading…
Reference in New Issue