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