Top Description Methods
org.hibernate.annotations

public @Interface SQLRestriction

extends Annotation
Annotations
@Target:TYPE, METHOD, FIELD
@Retention:RUNTIME
Imports
java.lang.annotation.Retention, .Target

Specifies a restriction written in native SQL to add to the generated SQL for entities or collections.

For example, @SQLRestriction could be used to hide entity instances which have been soft-deleted, either for the entity class itself:

@Entity
@SQLRestriction("status <> 'DELETED'")
class Document {
    ...
    @Enumerated(STRING)
    Status status;
    ...
}

or, at the level of an association to the entity:

@OneToMany(mappedBy = "owner")
@SQLRestriction("status <> 'DELETED'")
List<Document> documents;

The SQLJoinTableRestriction annotation lets a restriction be applied to an association table:

@ManyToMany
@JoinTable(name = "collaborations")
@SQLRestriction("status <> 'DELETED'")
@SQLJoinTableRestriction("status = 'ACTIVE'")
List<Document> documents;

Note that @SQLRestrictions are always applied and cannot be disabled. Nor may they be parameterized. They're therefore much less flexible than filters.

Authors
Gavin King, Emmanuel Bernard
Since
6.3
See Also
Filter, DialectOverride.SQLRestriction, SQLJoinTableRestriction

Method Summary

Modifier and TypeMethod and Description
public String
value()

A predicate, written in native SQL.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String value()

A predicate, written in native SQL.