Retrieving a list of objects with null in the properties after applying resultTransformer

In a criteria query I am getting a list of results in a right way.

As I dont want to all the fields from the entities projection is introduced to specify these fields. Ok, with projection is working fine but, instead of a List of entity is getting a list of object.

As I read, I need to apply setResultTransformer(ClassName.class). When resultTransformer is applied, a list of className are retrieved but all the atributes of the object are NULL. I have tried different parameters to the resultTransformer and always getting a list of object with null in all attributes.

Eg.:

criteria.setProjection(proList)
   .setResultTransformer( 
       new AliasToBeanResultTransformer(TramiteTrafico.class));

If not resultTransformer is applied getting values are right. Any idea why?

Thanks all!!

Answers


You need to have the property name of the class match the alias used in the projection list.

Something like list

class CatVO {
  String getCatName()  { ..}
  void setCatName(String catName) {..}
  String getKitName()  { ..}
  void setKitName(String kitName) {..}
}


List results = session.createCriteria(Domestic.class, "cat")
    .createAlias("kittens", "kit")
    .setProjection( Projections.projectionList()
        .add( Projections.property("cat.name"), "catName" )
        .add( Projections.property("kit.name"), "kitName" )
    ).setResultTransformer( 
       new AliasToBeanResultTransformer(CatVO.class))
     .list();

Need Your Help

Append a zero to value if necessary in SQL statement DB2

sql db2

I have a complex SQL statement that I need to match up two table based on a join. The the intial part of the complex query has a location number that is stored in a table as a Smallint and the sec...

ImportError: No module named dtmilano

android eclipse pydev jython androidviewclient

Hi I am new to python development. I am trying to execute the code given at http://dtmilano.blogspot.in/2012/02/monkeyrunner-interacting-with-views.html but when ever i am trying to execute the cod...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.