That is because you are tagging getSuperior with a @Column. That is wrong.
you must say whether it is OneToOne or OneToMany :) Even if it is a relation
with itself

On Tue, Mar 24, 2009 at 8:16 PM, emmettwalsh <emmettwa...@gmail.com> 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)
>
>
> --
> View this message in context:
> http://www.nabble.com/Hibernate-help-tp22688812s2369p22688812.html
> Sent from the AppFuse - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net
> For additional commands, e-mail: users-h...@appfuse.dev.java.net
>
>


-- 
Regards,
Kannan Ekanath

Reply via email to