i've user entity maintaining self-referencing manytomany relation represents user's friends. have entity, attribute, holding manytoone relation user entity.
now want retrieve, through namedquery, , given user u, user's friends whit exact attribute value.
what query?
i tried like:
"select a.user "+ "from attribute "+ "where a.attribute= :attribute , "+ "c.user in ( :user.friends )"
this give me null pointer exception during sessionfactory creation while initializing application.
here entities:
@entity public class user implements serializable { private static final long serialversionuid = 1l; @id private string id; private string nickname; private string thumbnailurl; @manytomany @jointable( name = "user_friends", joincolumns = @joincolumn(name = "user_id"), inversejoincolumns = @joincolumn(name = "friend_id") ) protected list<user> friends = new arraylist<user>(); @manytomany(mappedby = "friends") protected list<user> befriended = new arraylist<user>(); /* * getters , setters... */ } public class attribute implements serializable { /* * other fields... */ @manytoone @joincolumn(name="userid") private user user; /* * getters , setters */ }
Comments
Post a Comment