The problem I've found is that when you add the @LazyCollection(LazyCollectionOption.EXTRA) to a collection with a @Where clause, the collection no longer uses the @Where clause when you do a .size() on the collection.
I've provided my example files below:
Hibernate version: 3.2.6.ga
Mapping documents:
@Entity
@Table(name="site_quick")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class SiteQuick {
private List<SiteQuickPage> pageList;
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id){
this.id = id;
}
@OneToMany(mappedBy="site", fetch = FetchType.LAZY, cascade = javax.persistence.CascadeType.ALL)
@Where(clause = "is_draft = 0")
@LazyCollection(LazyCollectionOption.EXTRA)
public List<SiteQuickPage> getPageList() {
if (pageList == null){
pageList = new ArrayList<SiteQuickPage>();
}
return pageList;
}
}
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@Table(name = "site_quick_page")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@BatchSize(size = 10)
public class SiteQuickPage implements Serializable{
private Long id;
private boolean draft = false;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id){
this.id = id;
}
@Column(name = "is_draft", nullable = false)
public boolean isDraft() {
return draft;
}
public void setDraft(boolean draft) {
this.draft = draft;
}
}
Name and version of the database you are using:
MySQL 5.0.45
The generated SQL (show_sql=true):
Hibernate: select count(id) from site_quick_page where site_id =?
|