Hi I think I have Isolated the problem. It pretty much looks like FetchType.LAZY is not working for @ManyToOne associations in my case:
I wrote a small test that loads a Child Category, event though I have:
Code:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="parent_id")
public Category getParent() {
return parent;
}
All the parent are loaded, here is the test:
Code:
public class TestLoadRecursiveCategories extends TestCase{
private EntityService getEntityService() {
return (EntityService) RegistryBuilder.constructDefaultRegistry().getService(EntityService.class);
}
public void testLoadRecursiveCategories() {
EntityService db = getEntityService();
Category c = (Category) db.load(Category.class,203);
System.out.println("Originally asked only for: " + c.getId());
}
}
And this is the output:
Code:
1 with id 1 com.estudiowebs.CMS.domain.Category loaded so far
2 with id 3 com.estudiowebs.CMS.domain.Category loaded so far
3 with id 28 com.estudiowebs.CMS.domain.Category loaded so far
4 with id 170 com.estudiowebs.CMS.domain.Category loaded so far
5 with id 203 com.estudiowebs.CMS.domain.Category loaded so far
Originally asked only for: 203
As you can see even though FetcType is set to Lazy, all parents are being loaded all the way until it reaches de root. My intention is that no parents are loaded until requested by calling getParent();
Below is the class that I'm using:
Code:
@Entity
public class Category implements Serializable {
private java.lang.Integer id;
private java.lang.String title;
private Category parent;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="parent_id")
public Category getParent() {
return parent;
}
public void setParent(Category parent) {
this.parent = parent;
}
@Id(generate=GeneratorType.AUTO)
@Keyword(id=true)
public java.lang.Integer getId() {
return id;
}
public void setId(java.lang.Integer id) {
this.id = id;
}
}
I don't know if I am making a wrong assumption here, but if an association is set to Lazy should not be loaded until requested, right?