我使用休眠4.我寫一個過濾器。我注意到奇怪的是沒有得到應用的過濾器,如果我使用session.get()方法休眠濾波器session.get的情況下不工作(),但在session.createQuery的情況下工作()
public SecurityAgency getSecurityAgencyById(int id) {
Session session = this.sessionFactory.getCurrentSession();
session.enableFilter("byEnabled");
SecurityAgency s = (SecurityAgency)session.get(SecurityAgency.class, new Integer(id));
return s;
}
濾鏡開始,只要我更換session.createQuery方法session.get方法和發送工作HQL查詢。我無法在hibernate文檔中找到任何此行爲的原因。在securtiy代理類
filter聲明
@Entity
@Table(name="security_agency")
public class SecurityAgency implements java.io.Serializable {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name="name")
private String name;
@Column(name="code")
private String code;
@Column(name="website")
private String website;
@Column(name="tan")
private String tan;
@Column(name="email")
private String email;
@Column(name="pan")
private String pan;
@Column(name="created_at")
private Date createdAt;
@Column(name="created_by")
private long createdBy;
@Column(name="modified_at")
private Date modifiedAt;
@Column(name="modified_by")
private long modifiedBy;
@OneToMany(mappedBy="securityAgency",fetch = FetchType.EAGER)
@JsonIgnoreProperties("securityAgency")
@Filter(name = "byEnabled", condition = "is_enabled= 1")
private Set<ContactPerson> contactPersons = new HashSet<ContactPerson>(0);
public SecurityAgency() {
}
聯繫人類
@Entity
@Table(name = "contact_person")
@FilterDefs({
@FilterDef(name="byEnabled"),
@FilterDef(name="bySecurityAgency",parameters = @ParamDef(name="agency_id", type="int"))
})
@Filters({
@Filter(name="byEnabled", condition = "is_enabled = 1"),
@Filter(name="bySecurityAgency", condition = "agency_id= :agency_id ")
})
public class ContactPerson implements java.io.Serializable {
您能否顯示您的過濾器定義 – kuhajeyan
@kuhajeyan。我在編輯這個問題。但在這個博客的第四評論聲明,hibernate忽略過濾器的情況下獲取並加載https://ayende.com/blog/3993/nhibernate-filters。但我找不到這樣的任何文件 –
它應該得到很好,除非你已經標記爲禁用。你能否顯示你的SecurityAgency類以及如何應用過濾器 – kuhajeyan