HHH-18199 - Remove @Where and @WhereJoinTable

This commit is contained in:
Steve Ebersole 2024-07-24 07:44:40 -05:00
parent d1a824a701
commit 163d48d81c
29 changed files with 89 additions and 558 deletions

View File

@ -8,15 +8,6 @@ An occasional requirement seen in the wild is to never physically remove rows fr
instead perform a "soft delete" where a column is updated to indicate that the row is no longer active.
Hibernate offers first-class support for this behavior through its `@SoftDelete` annotation.
[NOTE]
====
The `@SoftDelete` annotation is new in 6.4.
It was possible to hack together support for soft deletes in previous versions using a combination of filters,
`@Where` and custom delete event handling. However, that approach was tedious and did not work in
all cases. `@SoftDelete` should be highly preferred.
====
Hibernate supports soft delete for both <<soft-delete-entity,entities>> and <<soft-delete-collection,collections>>.
Soft delete support is defined by 3 main parts -

View File

@ -263,33 +263,6 @@ public interface DialectOverride {
JoinFormula[] value();
}
/**
* Specializes a {@link org.hibernate.annotations.Where}
* in a certain dialect.
*
* @deprecated Use {@link SQLRestriction}
*/
@Target({METHOD, FIELD, TYPE})
@Retention(RUNTIME)
@Repeatable(Wheres.class)
@OverridesAnnotation(org.hibernate.annotations.Where.class)
@Deprecated(since = "6.3")
@interface Where {
/**
* The {@link Dialect} in which this override applies.
*/
Class<? extends Dialect> dialect();
Version before() default @Version(major = MAX_VALUE);
Version sameOrAfter() default @Version(major = MIN_VALUE);
org.hibernate.annotations.Where override();
}
@Target({METHOD, FIELD})
@Retention(RUNTIME)
@interface Wheres {
Where[] value();
}
/**
* Specializes a {@link org.hibernate.annotations.SQLRestriction}
* in a certain dialect.

View File

@ -1,78 +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 a restriction written in native SQL to add to the generated
* SQL for entities or collections.
* <p>
* For example, {@code @Where} could be used to hide entity instances which
* have been soft-deleted, either for the entity class itself:
* <pre>
* &#64;Entity
* &#64;Where(clause = "status &lt;&gt; 'DELETED'")
* class Document {
* ...
* &#64;Enumerated(STRING)
* Status status;
* ...
* }
* </pre>
* <p>
* or, at the level of an association to the entity:
* <pre>
* &#64;OneToMany(mappedBy = "owner")
* &#64;Where(clause = "status &lt;&gt; 'DELETED'")
* List&lt;Document&gt; documents;
* </pre>
* <p>
* The {@link WhereJoinTable} annotation lets a restriction be applied to
* an {@linkplain jakarta.persistence.JoinTable association table}:
* <pre>
* &#64;ManyToMany
* &#64;JoinTable(name = "collaborations")
* &#64;Where(clause = "status &lt;&gt; 'DELETED'")
* &#64;WhereJoinTable(clause = "status = 'ACTIVE'")
* List&lt;Document&gt; documents;
* </pre>
* <p>
* By default, {@code @Where} restrictions declared for an entity are also
* applied when loading associations of that entity type. This behavior can
* be disabled using the setting
* {@value org.hibernate.cfg.AvailableSettings#USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS}.
* However, this setting is now deprecated.
* <p>
* Note that {@code @Where} restrictions are always applied and cannot be
* disabled. Nor may they be parameterized. They're therefore <em>much</em>
* less flexible than {@linkplain Filter filters}.
*
* @see Filter
* @see DialectOverride.Where
* @see org.hibernate.cfg.AvailableSettings#USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS
* @see WhereJoinTable
*
* @author Emmanuel Bernard
*
* @deprecated Use {@link SQLRestriction}
*/
@Target({TYPE, METHOD, FIELD})
@Retention(RUNTIME)
@Deprecated(since = "6.3")
public @interface Where {
/**
* A predicate, written in native SQL.
*/
String clause();
}

View File

@ -1,45 +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.RetentionPolicy.RUNTIME;
/**
* Specifies a restriction written in native SQL to add to the generated SQL
* when querying the {@linkplain jakarta.persistence.JoinTable join table}
* of a collection.
* <p>
* For example, <code>&#64;WhereJoinTable("status &lt;&gt; 'DELETED'")</code>
* could be used to hide associations which have been soft-deleted from an
* association table.
*
* @apiNote This separate annotation is useful because it's possible to filter
* a many-to-many association <em>both</em> by a restriction on the
* join table, and, <em>simultaneously</em>, by a restriction on the
* associated entity table. The {@link Where @Where} annotation always
* filters entity tables.
*
* @author Emmanuel Bernard
*
* @see Where
*
* @deprecated Use {@link SQLJoinTableRestriction}
*/
@Target({METHOD, FIELD})
@Retention(RUNTIME)
@Deprecated(since = "6.3")
public @interface WhereJoinTable {
/**
* A predicate, written in native SQL.
*/
String clause();
}

View File

@ -72,8 +72,6 @@ import org.hibernate.annotations.SortComparator;
import org.hibernate.annotations.SortNatural;
import org.hibernate.annotations.SqlFragmentAlias;
import org.hibernate.annotations.Synchronize;
import org.hibernate.annotations.Where;
import org.hibernate.annotations.WhereJoinTable;
import org.hibernate.boot.BootLogging;
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
import org.hibernate.boot.model.TypeDefinition;
@ -168,10 +166,10 @@ import static org.hibernate.boot.model.internal.BinderHelper.createSyntheticProp
import static org.hibernate.boot.model.internal.BinderHelper.extractFromPackage;
import static org.hibernate.boot.model.internal.BinderHelper.getCascadeStrategy;
import static org.hibernate.boot.model.internal.BinderHelper.getFetchMode;
import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation;
import static org.hibernate.boot.model.internal.BinderHelper.getPath;
import static org.hibernate.boot.model.internal.BinderHelper.isDefault;
import static org.hibernate.boot.model.internal.BinderHelper.isPrimitive;
import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation;
import static org.hibernate.boot.model.internal.EmbeddableBinder.fillEmbeddable;
import static org.hibernate.boot.model.internal.GeneratorBinder.buildGenerators;
import static org.hibernate.boot.model.internal.PropertyHolderBuilder.buildPropertyHolder;
@ -1876,11 +1874,7 @@ public abstract class CollectionBinder {
private String getWhereJoinTableClause() {
final SQLJoinTableRestriction joinTableRestriction = property.getDirectAnnotationUsage( SQLJoinTableRestriction.class );
if ( joinTableRestriction != null ) {
return joinTableRestriction.value();
}
final WhereJoinTable whereJoinTable = property.getDirectAnnotationUsage( WhereJoinTable.class );
return whereJoinTable == null ? null : whereJoinTable.clause();
return joinTableRestriction != null ? joinTableRestriction.value() : null;
}
private String getWhereClause() {
@ -1895,16 +1889,7 @@ public abstract class CollectionBinder {
private String getWhereOnCollectionClause() {
final SQLRestriction restrictionOnCollection = getOverridableAnnotation( property, SQLRestriction.class, getBuildingContext() );
if ( restrictionOnCollection != null ) {
return restrictionOnCollection.value();
}
final Where whereOnCollection = getOverridableAnnotation( property, Where.class, buildingContext );
if ( whereOnCollection != null ) {
return whereOnCollection.clause();
}
return null;
return restrictionOnCollection != null ? restrictionOnCollection.value() : null;
}
private String getWhereOnClassClause() {
@ -1915,14 +1900,7 @@ public abstract class CollectionBinder {
SQLRestriction.class,
buildingContext
);
if ( restrictionOnClass != null ) {
return restrictionOnClass.value();
}
final Where whereOnClass = getOverridableAnnotation( property, Where.class, buildingContext );
if ( whereOnClass != null ) {
return whereOnClass.clause();
}
return null;
return restrictionOnClass != null ? restrictionOnClass.value() : null;
}
else {
return null;

View File

@ -54,7 +54,6 @@ import org.hibernate.annotations.Subselect;
import org.hibernate.annotations.Synchronize;
import org.hibernate.annotations.TypeBinderType;
import org.hibernate.annotations.View;
import org.hibernate.annotations.Where;
import org.hibernate.binder.TypeBinder;
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
import org.hibernate.boot.model.NamedEntityGraphDefinition;
@ -1630,10 +1629,6 @@ public class EntityBinder {
}
public void bindWhere() {
final Where where = getOverridableAnnotation( annotatedClass, Where.class, context );
if ( where != null ) {
this.where = where.clause();
}
final SQLRestriction restriction = getOverridableAnnotation( annotatedClass, SQLRestriction.class, context );
if ( restriction != null ) {
this.where = restriction.value();

View File

@ -45,8 +45,6 @@ import org.hibernate.boot.models.annotations.internal.OverriddenSQLSelectAnnotat
import org.hibernate.boot.models.annotations.internal.OverriddenSQLSelectsAnnotation;
import org.hibernate.boot.models.annotations.internal.OverriddenSQLUpdateAnnotation;
import org.hibernate.boot.models.annotations.internal.OverriddenSQLUpdatesAnnotation;
import org.hibernate.boot.models.annotations.internal.OverriddenWhereAnnotation;
import org.hibernate.boot.models.annotations.internal.OverriddenWheresAnnotation;
import org.hibernate.boot.models.annotations.internal.OverrideVersionAnnotation;
import org.hibernate.boot.models.internal.OrmAnnotationHelper;
import org.hibernate.models.internal.OrmAnnotationDescriptor;
@ -146,15 +144,6 @@ public interface DialectOverrideAnnotations {
OverriddenJoinFormulaAnnotation.class,
DIALECT_OVERRIDE_JOIN_FORMULAS
);
OrmAnnotationDescriptor<DialectOverride.Wheres, OverriddenWheresAnnotation> DIALECT_OVERRIDE_WHERES = new OrmAnnotationDescriptor<>(
DialectOverride.Wheres.class,
OverriddenWheresAnnotation.class
);
OrmAnnotationDescriptor<DialectOverride.Where, OverriddenWhereAnnotation> DIALECT_OVERRIDE_WHERE = new OrmAnnotationDescriptor<>(
DialectOverride.Where.class,
OverriddenWhereAnnotation.class,
DIALECT_OVERRIDE_WHERES
);
OrmAnnotationDescriptor<DialectOverride.SQLInserts, OverriddenSQLInsertsAnnotation> DIALECT_OVERRIDE_SQL_INSERTS = new OrmAnnotationDescriptor<>(
DialectOverride.SQLInserts.class,
OverriddenSQLInsertsAnnotation.class

View File

@ -645,14 +645,6 @@ public interface HibernateAnnotations {
View.class,
ViewAnnotation.class
);
OrmAnnotationDescriptor<Where,WhereAnnotation> WHERE = new OrmAnnotationDescriptor<>(
Where.class,
WhereAnnotation.class
);
OrmAnnotationDescriptor<WhereJoinTable,WhereJoinTableAnnotation> WHERE_JOIN_TABLE = new OrmAnnotationDescriptor<>(
WhereJoinTable.class,
WhereJoinTableAnnotation.class
);
static void forEachAnnotation(Consumer<AnnotationDescriptor<? extends Annotation>> consumer) {
OrmAnnotationHelper.forEachOrmAnnotation( HibernateAnnotations.class, consumer );

View File

@ -1,67 +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.DialectOverride;
import org.hibernate.annotations.Where;
import org.hibernate.boot.models.HibernateAnnotations;
import org.hibernate.boot.models.annotations.spi.AbstractOverrider;
import org.hibernate.boot.models.annotations.spi.DialectOverrider;
import org.hibernate.models.spi.AnnotationDescriptor;
import org.hibernate.models.spi.SourceModelBuildingContext;
import org.jboss.jandex.AnnotationInstance;
import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_WHERE;
import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue;
import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue;
/**
* @author Steve Ebersole
*/
@SuppressWarnings("ClassExplicitlyAnnotation")
public class OverriddenWhereAnnotation
extends AbstractOverrider<Where>
implements DialectOverride.Where, DialectOverrider<Where> {
private Where override;
public OverriddenWhereAnnotation(SourceModelBuildingContext sourceModelContext) {
}
public OverriddenWhereAnnotation(DialectOverride.Where source, SourceModelBuildingContext sourceModelContext) {
dialect( source.dialect() );
before( source.before() );
sameOrAfter( source.sameOrAfter() );
override( extractJdkValue( source, DIALECT_OVERRIDE_WHERE, "override", sourceModelContext ) );
}
public OverriddenWhereAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) {
super( source, DIALECT_OVERRIDE_WHERE, sourceModelContext );
override( extractJandexValue( source, DIALECT_OVERRIDE_WHERE, "override", sourceModelContext ) );
}
@Override
public AnnotationDescriptor<Where> getOverriddenDescriptor() {
return HibernateAnnotations.WHERE;
}
@Override
public Where override() {
return override;
}
public void override(Where value) {
this.override = value;
}
@Override
public Class<? extends Annotation> annotationType() {
return DialectOverride.Where.class;
}
}

View File

@ -1,54 +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.DialectOverride;
import org.hibernate.boot.models.annotations.spi.RepeatableContainer;
import org.hibernate.models.spi.SourceModelBuildingContext;
import org.jboss.jandex.AnnotationInstance;
import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_WHERES;
import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue;
import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue;
/**
* @author Steve Ebersole
*/
@SuppressWarnings("ClassExplicitlyAnnotation")
public class OverriddenWheresAnnotation
implements DialectOverride.Wheres, RepeatableContainer<DialectOverride.Where> {
private DialectOverride.Where[] value;
public OverriddenWheresAnnotation(SourceModelBuildingContext sourceModelContext) {
}
public OverriddenWheresAnnotation(DialectOverride.Wheres source, SourceModelBuildingContext sourceModelContext) {
value = extractJdkValue( source, DIALECT_OVERRIDE_WHERES, "override", sourceModelContext );
}
public OverriddenWheresAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) {
value = extractJandexValue( source, DIALECT_OVERRIDE_WHERES, "override", sourceModelContext );
}
@Override
public DialectOverride.Where[] value() {
return value;
}
@Override
public void value(DialectOverride.Where[] value) {
this.value = value;
}
@Override
public Class<? extends Annotation> annotationType() {
return DialectOverride.Wheres.class;
}
}

View File

@ -1,59 +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.Where;
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 WhereAnnotation implements Where {
private String clause;
/**
* Used in creating dynamic annotation instances (e.g. from XML)
*/
public WhereAnnotation(SourceModelBuildingContext modelContext) {
}
/**
* Used in creating annotation instances from JDK variant
*/
public WhereAnnotation(Where annotation, SourceModelBuildingContext modelContext) {
this.clause = annotation.clause();
}
/**
* Used in creating annotation instances from Jandex variant
*/
public WhereAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) {
this.clause = extractJandexValue( annotation, HibernateAnnotations.WHERE, "clause", modelContext );
}
@Override
public Class<? extends Annotation> annotationType() {
return Where.class;
}
@Override
public String clause() {
return clause;
}
public void clause(String value) {
this.clause = value;
}
}

View File

@ -1,59 +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.WhereJoinTable;
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 WhereJoinTableAnnotation implements WhereJoinTable {
private String clause;
/**
* Used in creating dynamic annotation instances (e.g. from XML)
*/
public WhereJoinTableAnnotation(SourceModelBuildingContext modelContext) {
}
/**
* Used in creating annotation instances from JDK variant
*/
public WhereJoinTableAnnotation(WhereJoinTable annotation, SourceModelBuildingContext modelContext) {
this.clause = annotation.clause();
}
/**
* Used in creating annotation instances from Jandex variant
*/
public WhereJoinTableAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) {
this.clause = extractJandexValue( annotation, HibernateAnnotations.WHERE_JOIN_TABLE, "clause", modelContext );
}
@Override
public Class<? extends Annotation> annotationType() {
return WhereJoinTable.class;
}
@Override
public String clause() {
return clause;
}
public void clause(String value) {
this.clause = value;
}
}

View File

@ -454,7 +454,7 @@ public interface MappingSettings {
String DEFAULT_LIST_SEMANTICS = "hibernate.mapping.default_list_semantics";
/**
* The {@link org.hibernate.annotations.Where @Where} annotation specifies a
* The {@link org.hibernate.annotations.SQLRestriction @SQLRestriction} annotation specifies a
* restriction on the table rows which are visible as entity class instances or
* collection elements.
* <p>

View File

@ -16,7 +16,7 @@ import org.hibernate.sql.ast.tree.from.TableGroup;
import org.hibernate.sql.ast.tree.predicate.Predicate;
/**
* Things that can have {@link org.hibernate.annotations.Where},
* Things that can have {@link org.hibernate.annotations.SQLRestriction},
* and/or {@link org.hibernate.annotations.Filter} applied to them.
* This is effectively {@linkplain EntityMappingType entities} and
* {@linkplain PluralAttributeMapping plural attributes}.

View File

@ -13,7 +13,7 @@ import org.hibernate.sql.ast.tree.from.TableGroup;
import org.hibernate.sql.ast.tree.predicate.Predicate;
/**
* Things which can have {@link org.hibernate.annotations.Where}
* Things which can have {@link org.hibernate.annotations.SQLRestriction}
* declarations - entities and collections
*
* @see FilterRestrictable
@ -26,7 +26,7 @@ public interface WhereRestrictable {
boolean hasWhereRestrictions();
/**
* Apply the {@link org.hibernate.annotations.Where} restrictions
* Apply the {@link org.hibernate.annotations.SQLRestriction} restrictions
*/
void applyWhereRestrictions(
Consumer<Predicate> predicateConsumer,

View File

@ -1167,7 +1167,7 @@ public abstract class AbstractCollectionPersister
}
/**
* Applies all defined {@link org.hibernate.annotations.Where}
* Applies all defined {@link org.hibernate.annotations.SQLRestriction}
*/
private static void applyWhereFragments(Consumer<Predicate> predicateConsumer, String alias, String template) {
if ( template == null ) {

View File

@ -9,7 +9,7 @@ package org.hibernate.sql;
import org.hibernate.Internal;
/**
* For a complete predicate. E.g. {@link org.hibernate.annotations.Where}
* For a complete predicate. E.g. {@link org.hibernate.annotations.SQLRestriction}
*
* @author Steve Ebersole
*/

View File

@ -91,7 +91,7 @@ public class SimpleSelect implements RestrictionRenderingContext {
}
/**
* Appends a complete {@linkplain org.hibernate.annotations.Where where} condition.
* Appends a complete {@linkplain org.hibernate.annotations.SQLRestriction where} condition.
* The {@code condition} is added as-is.
*/
public SimpleSelect addWhereToken(String condition) {

View File

@ -21,8 +21,8 @@ import org.hibernate.annotations.OptimisticLock;
import org.hibernate.annotations.OptimisticLockType;
import org.hibernate.annotations.OptimisticLocking;
import org.hibernate.annotations.ParamDef;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.annotations.SelectBeforeUpdate;
import org.hibernate.annotations.Where;
import jakarta.persistence.Convert;
import jakarta.persistence.ElementCollection;
@ -43,7 +43,7 @@ import jakarta.persistence.Table;
@SelectBeforeUpdate
@DynamicInsert @DynamicUpdate
@OptimisticLocking(type = OptimisticLockType.ALL)
@Where(clause = "1=1")
@SQLRestriction("1=1")
@FilterDef(name = "minLength", parameters = {@ParamDef(name = "minLength", type = Integer.class)})
@Filter(name = "betweenLength")
@Filter(name = "minLength", condition = ":minLength <= length")

View File

@ -2,16 +2,17 @@ package org.hibernate.orm.test.extralazy;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.SQLRestriction;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Where;
@Entity
@Table(name = "championship")
public class Championship {
@ -21,7 +22,7 @@ public class Championship {
@OneToMany(cascade = CascadeType.ALL)
@LazyCollection(LazyCollectionOption.EXTRA)
@Where(clause = " gpa >= 4 ")
@SQLRestriction(" gpa >= 4 ")
private List<Student> students = new ArrayList<>();
public Championship() {}

View File

@ -4,16 +4,17 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.SQLRestriction;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.MapKey;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Where;
@Entity
@Table(name = "school")
public class School {
@ -27,12 +28,12 @@ public class School {
@OneToMany(mappedBy = "school")
@LazyCollection(LazyCollectionOption.EXTRA)
@Where(clause = " gpa >= 4 ")
@SQLRestriction(" gpa >= 4 ")
private Set<Student> topStudents = new HashSet<Student>();
@OneToMany(mappedBy = "school")
@LazyCollection(LazyCollectionOption.EXTRA)
@Where(clause = " gpa >= 4 ")
@SQLRestriction(" gpa >= 4 ")
@MapKey
private Map<String, Student> studentsMap = new HashMap<>();

View File

@ -7,12 +7,21 @@
package org.hibernate.orm.test.hql.size;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.jdbc.Expectation;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
@ -22,18 +31,8 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.TypedQuery;
import org.hibernate.annotations.ResultCheckStyle;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.annotations.Where;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.jdbc.Expectation;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
@TestForIssue(jiraKey = "HHH-14585")
@RequiresDialect(value = PostgreSQLDialect.class, comment = "Other databases may not support boolean data types")

View File

@ -2,6 +2,19 @@ package org.hibernate.orm.test.insertordering;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.annotations.SortNatural;
import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorValue;
@ -15,19 +28,6 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.OneToMany;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.annotations.SortNatural;
import org.hibernate.annotations.Where;
import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.Test;
/**
* @author Normunds Gavars
* @author Nathan Xu

View File

@ -3,7 +3,7 @@ package org.hibernate.orm.test.mapping.where;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.annotations.Where;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jira;
@ -139,7 +139,7 @@ public class WhereAnnotationAndJoinedInheritanceTest {
@Entity(name = "Parent")
@Inheritance(strategy = InheritanceType.JOINED)
@Where(clause = "deleted_column is null")
@SQLRestriction("deleted_column is null")
public static abstract class Parent {
@Id

View File

@ -9,7 +9,6 @@ package org.hibernate.orm.test.mapping.where;
import java.util.Map;
import org.hibernate.Hibernate;
import org.hibernate.annotations.Where;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.graph.spi.RootGraphImplementor;
@ -34,8 +33,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests for {@link Where} handling.
*
* @implNote Requires H2 simply because we need hard-coded schema export. The schema is simple and would
* probably work on a larger number of databases; but there should really be nothing database specific in
* these tests.

View File

@ -1,12 +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
*/
/**
* Tests for {@link org.hibernate.annotations.Where}
*/
package org.hibernate.orm.test.mapping.where;

View File

@ -8,6 +8,10 @@ package org.hibernate.orm.test.envers.entities.manytomany.sametable;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.annotations.SQLJoinTableRestriction;
import org.hibernate.envers.Audited;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
@ -16,10 +20,6 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import org.hibernate.annotations.SQLJoinTableRestriction;
import org.hibernate.annotations.WhereJoinTable;
import org.hibernate.envers.Audited;
/**
* @author Adam Warski (adam at warski dot org)
*/

View File

@ -8,6 +8,19 @@ package org.hibernate.orm.test.envers.integration.manytomany;
import java.util.Set;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.envers.AuditJoinTable;
import org.hibernate.envers.Audited;
import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase;
import org.hibernate.orm.test.envers.Priority;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.hibernate.testing.transaction.TransactionUtil;
import org.junit.Test;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorType;
import jakarta.persistence.DiscriminatorValue;
@ -19,32 +32,14 @@ import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.annotations.Where;
import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.envers.AuditJoinTable;
import org.hibernate.envers.Audited;
import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase;
import org.hibernate.orm.test.envers.Priority;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.hibernate.testing.transaction.TransactionUtil;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Provides test cases for the following {@link ManyToMany} mapping:
*
* <ul>
* <li>An {@link AuditJoinTable} with a {@link Where} clause.</li>
* <li>A non join-table mapping with a {@link Where} clause.</li>
* </ul>
* Provides test cases for the following {@link ManyToMany} mapping with {@linkplain SQLRestriction}
*
* @author Chris Cranford
*/
@TestForIssue(jiraKey = "HHH-9432")
@JiraKey("HHH-9432")
@SkipForDialect( dialectClass = AltibaseDialect.class, reason = "'TYPE' is not escaped even though autoQuoteKeywords is enabled")
public class BasicWhereTest extends BaseEnversJPAFunctionalTestCase {
private Integer aId;

View File

@ -8,6 +8,19 @@ package org.hibernate.orm.test.envers.integration.onetomany;
import java.util.Set;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.envers.AuditJoinTable;
import org.hibernate.envers.Audited;
import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase;
import org.hibernate.orm.test.envers.Priority;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.hibernate.testing.transaction.TransactionUtil;
import org.junit.Test;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorType;
import jakarta.persistence.DiscriminatorValue;
@ -19,34 +32,15 @@ import jakarta.persistence.JoinTable;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.annotations.Where;
import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.envers.AuditJoinTable;
import org.hibernate.envers.Audited;
import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase;
import org.hibernate.orm.test.envers.Priority;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.hibernate.testing.transaction.TransactionUtil;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Provides test cases for the following {@link OneToMany} mapping:
*
* <ul>
* <li>An {@link AuditJoinTable} with a {@link Where} clause.</li>
* <li>A non join-table mapping with a {@link Where} clause.</li>
* </ul>
* Provides test cases for the following {@link OneToMany} mapping with {@linkplain SQLRestriction}
*
* @author Chris Cranford
*/
@TestForIssue(jiraKey = "HHH-9432")
@JiraKey("HHH-9432")
@SkipForDialect( dialectClass = AltibaseDialect.class, reason = "'TYPE' is not escaped even though autoQuoteKeywords is enabled")
public class BasicWhereTest extends BaseEnversJPAFunctionalTestCase {
private Integer aId;