-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Transform subentitites to dto using Transformers.aliasToBean
PostPosted: Thu Mar 29, 2012 12:26 pm 
Newbie

Joined: Mon Nov 15, 2010 2:09 pm
Posts: 2
Hello,

I'd like to have an entity to be transformed into a DTO AND some of its related associated entities (collections) also transformed into their own DTO, using Hibernate "Transformers.aliasToBean".

I know how to transform a simple entity to a DTO using projections to map entity fields to DTO fields, but I would like to transform on the fly associated entities too.

Here is my main entity :

Code:
Panel{
Long panelId;
String panelName;
Long panelSize;
Collection<Experiment> experiments;
Collection<Lot> lots;
...
}


Here are the associated entities I'd like to transform to DTO on the fly:

Code:
Experiment{
Long experimentId;
String experimentName;
...
}


Code:
Lot{
Long lotId;
String description ;
String lotNumber;
...
}




Here are DTOs I'd like to obtain:

Code:
PanelDTO{
Long panelId ;
String panelName;
Long panelSize ;
Collection<ExperimentDTO> experiments;
Collection<LotDTO> lots ;
...
}


Using following DTO to transform on the fly in PanelDao class:

Code:
ExperimentDTO{
Long experimentId ;
String experimentName;
...
}



Code:
LotDTO{
Long lotId;
String description ;
String lotNumber;
...
}



Would you mind hint me to know what to update in following code to transform on the fly experiments and lots collection to collections of DTO?
Code:
protected findPanel() throws Exception{
      Criteria crit = getSession().createCriteria(Panel.class, "p");

      ProjectionList projectionList = Projections.projectionList();
      projectionList.add(Projections.distinct(Projections.id()));
      projectionList.add(Projections.property("p.panelName"), "panelName");
      projectionList.add(Projections.property("p.panelSize"), "size");
      projectionList.add(Projections.property("p.experiments"), "experiments");
      projectionList.add(Projections.property("p.lots"), "lots");

      crit.setProjection(projectionList);

      crit.setResultTransformer(Transformers.aliasToBean(PanelVO.class));

      return crit.list()
}


Thanks a lot for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.