When i pull children categories from class instance with .getChildren, i get correct list of children but with some null elements in the beginning. Number of these null elements depends on amount of records in table. But when i execute generated SQL in MySQL client, i get correct resultset. Without null recodrs. Have any ideas?
Class(simplified):
Code:
public class Category extends BaseObject {
private Long id;
private String name;
private List<Category> children;
private Category parent;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<Category> getChildren() {
return children;
}
public void setChildren(List<Category> children) {
this.children = children;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Category getParent() {
return parent;
}
public void setParent(Category parent) {
this.parent = parent;
}
}
Mapping:
Code:
<hibernate-mapping>
<class name="com.homeatworld.model.directory.Category" table="cat_categories">
<id name="id" column="id" unsaved-value="null">
<generator class="native"/>
</id>
<list name="children" lazy="true" cascade="none">
<key column="parent_id"/>
<index column="listOrder"/>
<one-to-many class="com.homeatworld.model.directory.Category"/>
</list>
<property name="name" column="name"/>
<many-to-one name="parent" class="com.homeatworld.model.directory.Category" column="parent_id"/>
</class>
</hibernate-mapping>
SQL:
select children0_.parent_id as parent9_1_, children0_.id as id1_, children0_.id as id284_0_, children0_.name as name284_0_, children0_.parent_id as parent9_284_0_ from cat_categories children0_ where children0_.parent_id=?