Hibernate JPA @FilterDef Example

@FilterDef

The @FilterDef annotation is used to specify a @Filter definition (name, default condition and parameter types, if any).

FilterDef
Filter definition. Defines a name, default condition and parameter types (if any).

@Filter mapping entity-level usage

@Entity(name = "Account")
@Table(name = "account")
@FilterDef(
    name="activeAccount",
    parameters = @ParamDef(
        name="active",
        type="boolean"
    )
)
@Filter(
    name="activeAccount",
    condition="active_status = :active"
)
public static class Account {

    @Id
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    private Client client;

    @Column(name = "account_type")
    @Enumerated(EnumType.STRING)
    private AccountType type;

    private Double amount;

    private Double rate;

    @Column(name = "active_status")
    private boolean active;

    //Getters and setters omitted for brevity
}

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations