-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Potential Bug in Lazy Collections
PostPosted: Wed Apr 23, 2008 3:12 pm 
Newbie

Joined: Fri Mar 09, 2007 2:01 am
Posts: 5
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 =?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.