Jerson -

What I would likely suggest you consider is creating a DTO object that
resembles your result from the SQLQuery.  You can then use one of the
stock Hibernate Transformers to convert the SQL results into instances
of this DTO Bean and then you can return the beans to your view to
iterate over.

Here's a simple example:

public List getQueryUsingResultTransformer() {
  SQLQuery query = session.createSQLQuery("SELECT SOME FANCY DATA");
  /* do other stuff */
  query.setResultTransformer(new
AliasToBeanResultTransformer(YourDTO.class));
  return(query.list());
}

Another alternative would be to iterate the result set yourself 

public List<YourDTO> getQueryDoingSelfInstantiation() {
  List<YourDTO> myList = new ArrayList<YourDTO>();
  SQLQuery query = session.createSQLQuery("SELECT SOME FANCY DATA");
  /* do other stuff */
  List results = query.list();
  Iterator i = results.iterator();
  while(i.hasNext())
  {
    Object[] row = (Object[]) i.next();
    /* each row has a 0-based index for each column of query */
    YourDTO dto = new YourDTO();
    /* set values on dto */
    myList.add(dto);
  }
  return(myList);
}

Both basically do the same; however I find that using the AliasToBean
transformer is much cleaner code :)

Chris

> -----Original Message-----
> From: Jerson John [mailto:jer...@cprvision.com]
> Sent: Thursday, February 17, 2011 7:43 PM
> To: user@struts.apache.org
> Subject: generate SQL Hibernate Query using session
> 
> Hi,
>   I am trying to generate SQL query using session.createSQLQuery and
> returning the list object..This select query contains joins and so it
> cannot
> be mapped to any of my model objects.How can I now get the values in
my
> jsp
> page using iterator tag in Struts 2...
> 
> Please help me on this
> 
> Many Thanks and Regards,
> 
> Jerson
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to