java - Hibernate, Criteria, Projection, Transformer.aliasToBean and List<T> issue -


i want select entity determined fields. other fields let null. issue...

enta has refences entb , list of entc.


class enta {     @id     @genericgenerator(name = "unique_id", strategy = "uuid")     @generatedvalue(generator = "unique_id")     @column(name = "id", nullable = false, length = 32, unique = true)     private string id;     @onetoone(fetch = fetchtype.lazy)     @joincolumn(name = "entbs", nullable = false, unique = false)     private entb entb;     @onetomany(mappedby = "entcs", fetch = fetchtype.lazy)     @ondelete(action = ondeleteaction.cascade)     @jsonignore     private list<entc> listentc;     ... other fields , getters & setters ... } 

a few days ago had complemented bacis procedure of selection folowing code. code provides selection object determined fields, other fields null. sql`s "select fielda, fieldj table ..."


public list<enta> select(..., list<string> fieldlist, ...) {     criteria crit = sessionfactory.getcurrentsession().createcriteria(enta.class);      ...      projectionlist pl = projections.projectionlist();     (string prop : fieldlist) {         pl.add(projections.property(prop), prop);     }     crit.setprojection(pl);     crit.setresulttransformer(transformers.aliastobean(enta.class));      ...      return crit.list(); } 

all works good, example: select fields (not in entity) repeat field. result = object of class enta has fields "id","entb" , "other_field_name" values, other fields null.


list<string> fieldlist = new arraylist<string>(); fieldlist.add("id"); fieldlist.add("entb"); fieldlist.add("entb"); fieldlist.add("entb"); fieldlist.add("other_field_name"); select(..., fieldlist, ...);  
 hibernate:      /* criteria query */ select         this_.id y0_,         this_.entb y1_,         this_.entb y2_,         this_.entb y3_,         this_.other_field_name y4_             enta this_ hibernate:      select         entb0_.id id1_12_0_,         entb0_.idx idx2_12_0_,         entb0_.name name3_12_0_              entb entb0_              entb0_.id=? 

but...


fieldlist.add("id"); fieldlist.add("listentc"); select(..., fieldlist, ...); 
 hibernate:      /* criteria query */ select         this_.id y0_,         this_.id y1_              enta this_ java.lang.arrayindexoutofboundsexception: 1     @ org.hibernate.loader.criteria.criterialoader.getresultrow(criterialoader.java:168)     @ org.hibernate.loader.criteria.criterialoader.getresultcolumnorrow(criterialoader.java:148)     @ org.hibernate.loader.loader.getrowfromresultset(loader.java:753)     @ org.hibernate.loader.loader.processresultset(loader.java:952)     @ org.hibernate.loader.loader.doquery(loader.java:920)     @ org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:354)     @ org.hibernate.loader.loader.dolist(loader.java:2553)     @ org.hibernate.loader.loader.dolist(loader.java:2539)     @ org.hibernate.loader.loader.listignorequerycache(loader.java:2369)     @ org.hibernate.loader.loader.list(loader.java:2364)     @ org.hibernate.loader.criteria.criterialoader.list(criterialoader.java:126)     @ org.hibernate.internal.sessionimpl.list(sessionimpl.java:1682)     @ org.hibernate.internal.criteriaimpl.list(criteriaimpl.java:380)     *************************************.select(basedao.java:141) 

several days debug code & hibernate-core sources , cant understand:
if use simple selection without projections , transformers, normal object of enta list<entc> lstentc has values
if use projection without transformers - not enta
if use projection transformers, can select non-list fields

have ideas how use criteria`s selection projection result class? thanks.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -