hiberater @filter参数枚举类型

时间:2018-03-28 12:38:09

标签: java hibernate filter

如何在休眠中将@filter参数类型设置为枚举?

Hibernate版本5.3.x

@FilterDef(name = "my_filter", parameters = {
@ParamDef(name = "status", type = "what should be here? ") 
})
@Filter(name = "my_filter", condition = "status = :status")
@Entity
public class MyEntity{
  ....
  private MyStatus status;
  ....

}

enum

public enum MyStatus{
   STATUS1,STATUS2
}

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

类上的过滤器定义:

@FilterDef(name = "my_filter", parameters = {
     @ParamDef(name = "state", type = "string") 
     })
@Filter(name = "my_filter", condition = "status = :status")
@Entity
public class MyEntity{
  ....
  private MyStatus status;
  ....

}

启用过滤器:

session.enableFilter("my_filter").setParameter("state", MySatus.STATUS1.toString());