java - Hibernate criteria: dto as entity -
i have query built hibernate criteria (i show "main" part):
criteria criteria = sessionprovider.get().createcriteria(user.class); // add other stuff query joins, group-bys, order-bys etc. // in projection list add "id" of user. projectionlist.add(projections.property("id"), "id"); // using same entity class user dto criteria.setresulttransformer(transformers.aliastobean(user.class));
so can do:
list<user> users = criteria.list();
problem comes when try load values entities. example:
users.get(0).getfirstname();
returns null. entities created "dtos" transformers.aliastobean have received "id" projection not working normal entities loaded get/load/etc.
is there way make these dto "working" entities?
seems passing argument in projectionlist wrong, need modify projectionlist this.
criteria criteria = sessionprovider.get().createcriteria(user.class); //add other stuff query joins, group-bys, order-bys etc. //in projection list add columns name mapped entity projectionlist projectionlist = projections.projectionlist(); projectionlist.add(projections.property("id")); projectionlist.add(projections.property("firstname")); criteria.setprojection(projectionlist); list<user> results = criteria.list(); //output results for(user user : results) { user.getfirstname(); }
Comments
Post a Comment