-->
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.  [ 3 posts ] 
Author Message
 Post subject: Single class Category tree mapping
PostPosted: Mon Mar 05, 2007 9:39 am 
Newbie

Joined: Mon Mar 05, 2007 9:04 am
Posts: 6
Location: Belarus
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=?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 1:13 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
What do you call a null element? You mean when you iterate through the list it.next() sometimes returns null???

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 1:52 pm 
Newbie

Joined: Mon Mar 05, 2007 9:04 am
Posts: 6
Location: Belarus
thanks for reply,

yes, i iterate with <c:foreach> and get those null elements outputed.
also list.size() counts them


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

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.