java - EnityManager query returns a strange unaccessible object -


i have 2 entities connected through join annotations , works fine except query result strange.

so have class cat , other class home. if execute named query of class cat expect it's property cat.home populated query result table home.

i'm executing query way:

list<cat> = (list<cat>) em.createnamedquery("cat.findhome")             .setparameter("catname", catname)             .setparameter("housekey", housekey).getresultlist(); 

and result is:

a = arraylist<e>        elementdata= object[10] (id=22688)            [0] = object[2] (id=22692)               [0] = cat (id=22692)               [1] = home (id=22692)            [1] = null            [2] = null            [3] = null            [4] = null            [5] = null            ...            [9] = null 

so question how can access 2 objects cat , home, , how come i'm getting result entity manager , not single object cat home in cat.home

entities:

cat.java - cat entity

//imports here  @entity @table(name="cat") @namedquery(name="cat.findhome",          query="from cat join a.home p a.name = :catname , p.housekey :housekey") public class cat implements serializable{  private static final long serialversionuid = 1l; private string catkey; private string name;  public list<home> key; // cat can have many homes  /**  * @param catkey catkey set  */ public void setcatkey(string catkey) {     this.catkey = catkey; }  /**  * @return catkey  */ @id @column(name="k_cat") public string getcatkey() {     return catkey; }  /**  * @return name  */ @column(name="name") public string getname() {     return name; }  /**  * @param name name set  */ public void setname(string name) {     this.name = name; }  /**  * @param home home set  */ public void sethome(list<home> home) {     this.home = home; }  /**  * @return home  */ @onetomany(cascade=cascadetype.all, fetch=fetchtype.lazy, mappedby="cat") @filter(name="contrfilter",condition = "k_cat=:kcathome") public list<home> gethome() {         return home;     } } 

home.java - home entity

   @entity @table(name="home") public class home implements serializable{      private static final long serialversionuid = 1l;  private sting housekey; private cat cat;  /**  * @param housekey housekey set  */ public void sethousekey(string housekey) {     this.housekey = housekey; }  /**  * @return housekey  */ @id @column(name="k_home") public string gethousekey(){     return housekey; }  /**  * @param cat cat set  */ public void setcat(cat cat) {     this.cat = cat; }  /**  * @return cat  */ @manytoone(fetch = fetchtype.lazy) @joincolumn(name = "k_cat_home", updatable=false, insertable=false) public cat getcat() {         return cat;     } } 

thanks in advance!

add select part named query

 query="select cat a.name = :catname , a.home.housekey :housekey") 

Comments