I am using JPA with Hibernate as a JPA provider. I cannot figure out how to configure my objects to apply the sleep filter to a one-to-many association.
I have Mastera collection Details. Here are my entity definitions:
@Entity
public class Master extends Base {
private List<Detail> details;
@OneToMany
@OrderColumn
@JoinTable(name = "master_details")
@Filter(name = "notDeleted")
public List<Detail> getDetails() {
return details;
}
public void setDetails(List<Detail> details) {
this.details = details;
}
}
@Entity
@FilterDef(name = "notDeleted", defaultCondition = "deleted = false")
public class Detail extends Base {
private Boolean deleted = false;
public Boolean getDeleted() {
return deleted;
}
public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}
}
Basenothing special but simple MappedSuperClass:
@MappedSuperclass
public class Base {
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
When uploading Masterto the entityManager.find(Master.class, mid)filter, I should forbid everyone to download Details, but I checked the sql queries generated by sleeping (by show_sql=true), and the where clause was not added when loading the details wizard !!! Sample request generated by sleep mode:
select
details0_.Master_id as Master1_6_1_,
details0_.details_id as details2_1_,
details0_.details_ORDER as details3_1_,
detail1_.id as id7_0_,
detail1_.deleted as deleted7_0_,
from
master_details details0_
inner join
Detail detail1_
on details0_.details_id=detail1_.id
where
details0_.Master_id=?
, " id , ", , : (
entityManager.createQuery("from Master where id=" + mid).getSingleResult();
@Where getDetails ( @Filter), , ( @Where)