looks good. standard is lazy

emmettwalsh wrote:
> thanks folks, after a lot of playing about the following seems to work (to
> get the parents and the children objs), Im just worried though that in a
> table with a lot of associated users, that hibernate is 'eagerly' building
> up a huge object graph before I call the 'gets, or is it lazy by default
>
>
> @Table(name = "user")
> public class User implements Serializable {
>
>       private Long id;
>       private String username;
>       
>       private User superior;
>       private Set<User> subordinates = new HashSet<User>();
>       
>       
>       @OneToMany(mappedBy="superior")
>       public Set<User> getSubordinates() {
>               return subordinates;
>       }
>
>       public void setSubordinates(Set<User> subordinates) {
>               this.subordinates = subordinates;
>       }
>
>       
>       @ManyToOne
>       @JoinColumn
>       public User getSuperior() {
>               return superior;
>       }
>       
>
>       public void setSuperior(User superior) {
>               this.superior = superior;
>       }
>       
>       
>
>
>
>
>
>
>
> tibi wrote:
>   
>> that is correct.
>> and when you add the @manytoone
>> the type will change from blob to int
>> and will be to foreign key to superior
>>
>> tibi
>>
>>
>> emmettwalsh wrote:
>>     
>>> but I have to have a superior column as that will hold the id to the
>>> 'parent' user ...?
>>>
>>>
>>>
>>> emmettwalsh wrote:
>>>   
>>>       
>>>> Hi, can anyone help me with this seemingly simple relationship Im trying
>>>> to model
>>>>
>>>> Basically I have a User class/object - which maps to a User table. I
>>>> want
>>>> each user to contain a reference to a superior User and also a reference
>>>> to a List of subordinate users. 
>>>>
>>>> When I load a user from the database I want all this information
>>>> contained
>>>> in the User object without having to do any extra queries, but unsure if
>>>> its possible, here is what I have so far. Can anyone tell me if I am on
>>>> thr right track ...
>>>>
>>>>
>>>> @Entity
>>>> @Table(name = "user")
>>>> public class User implements Serializable {
>>>>
>>>>    private Long id;
>>>>    private String username;
>>>>    
>>>>    private User superior;
>>>>    private Set<User> subordinates = new HashSet<User>();
>>>>
>>>>    @OneToMany(mappedBy="user",cascade=CascadeType.ALL)
>>>>    public Set<User> getSubordinates() {
>>>>            return subordinates;
>>>>    }
>>>>
>>>>
>>>>    @Column(nullable=true)
>>>>    public User getSuperior() {
>>>>            return superior;
>>>>    }
>>>>
>>>>
>>>> the annotations created a tinyblob for some reason for the superior
>>>> field
>>>>
>>>> mysql> desc user;
>>>> +----------+-------------+------+-----+---------+----------------+
>>>> | Field         | Type           | Null   | Key  | Default | Extra         
>>>> |
>>>> +----------+-------------+------+-----+---------+----------------+
>>>> | id              | bigint(20)   | NO    | PRI  | NULL    |
>>>> auto_increment
>>>> | 
>>>> | superior     | tinyblob      | YES  |         | NULL    |               
>>>> | 
>>>> | username  | varchar(50) | NO   | UNI   | NULL    |                | 
>>>> +----------+-------------+------+-----+---------+----------------+
>>>> 3 rows in set (0.00 sec)
>>>>
>>>>
>>>>
>>>>     
>>>>         
>>>   
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net
>> For additional commands, e-mail: users-h...@appfuse.dev.java.net
>>
>>
>>
>>     
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net
For additional commands, e-mail: users-h...@appfuse.dev.java.net

Reply via email to