RE: generate SQL Hibernate Query using session
Hi, Can u suggest me the best way to use datetime picker tag...It seems normal Struts 2 Tag Library does not have this... Many Thanks and Regards, Jerson CPR Vision Management Pte Ltd CRM Software & Marketing E: jer...@cprvision.com T: + (65) 6535 0996 F: + (65) 6327 8085 www.cprvision.com CPR Vision - Nominated finalist for CRM, Marketing & Loyalty "Agency of the Year" Award - Organized by Marketing Magazine -Original Message- From: CRANFORD, CHRIS [mailto:chris.cranf...@setech.com] Sent: Friday, February 18, 2011 11:23 AM To: Struts Users Mailing List Subject: RE: generate SQL Hibernate Query using session 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 getQueryDoingSelfInstantiation() { List myList = new ArrayList(); 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 - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: generate SQL Hibernate Query using session
Hi, It was really a great help from you guys...Thanks a lotfinally I manged to do some way.. Appreciate ur help... Many Thanks and Regards, Jerson -Original Message- From: CRANFORD, CHRIS [mailto:chris.cranf...@setech.com] Sent: Friday, February 18, 2011 11:23 AM To: Struts Users Mailing List Subject: RE: generate SQL Hibernate Query using session 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 getQueryDoingSelfInstantiation() { List myList = new ArrayList(); 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 - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: generate SQL Hibernate Query using session
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 getQueryDoingSelfInstantiation() { List myList = new ArrayList(); 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
Re: generate SQL Hibernate Query using session
I think you may use the Composite Class in Hibernate. Query q = session.createQuery (" select new NewCompositeClass(members, classInfo.className) " + " from Members members, ClassInfo classInfo " + " where members.level = classInfo.classCode "); and you need a class:NewCompositeClass.java Regards, Mead
RE: generate SQL Hibernate Query using session
Hi, By the way My query is below "select b.Name as brand,a.Name as eventname,c.Code,a.EventStartDate,a.EventEndDate,a.EventObjective,a.EventTyp e from ASSET a,Brand b,LPDCOUNTRY c where a.Brand=b.id and a.Country=c.id" It also says brand property not defined...Is there any syntax error...I couldn't find any Thanks in advance Many Thanks and Regards, Jerson From: Jerson John [mailto:jer...@cprvision.com] Sent: Friday, February 18, 2011 10:53 AM To: 'Struts Users Mailing List' Subject: RE: generate SQL Hibernate Query using session Hi, Thanks for your reply. Actually I am bit confused here..What I do normally is that get the List of the model calss from the HQL Query and cast it and iterate it in jsp...Here If there values from more than one table then I can't cast it to any model class because of the difference in properties.Please advice me a approach for thisThanks in advance Many Thanks and Regards, Jerson -Original Message- From: Dave Newton [mailto:davelnew...@gmail.com] Sent: Friday, February 18, 2011 10:34 AM To: Struts Users Mailing List Subject: Re: generate SQL Hibernate Query using session What does having joins have to do with not being able to map to your data model? Dave On Feb 17, 2011 8:43 PM, "Jerson John" wrote: > 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 - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: generate SQL Hibernate Query using session
Hi, Thanks for your reply. Actually I am bit confused here..What I do normally is that get the List of the model calss from the HQL Query and cast it and iterate it in jsp...Here If there values from more than one table then I can't cast it to any model class because of the difference in properties.Please advice me a approach for thisThanks in advance Many Thanks and Regards, Jerson -Original Message- From: Dave Newton [mailto:davelnew...@gmail.com] Sent: Friday, February 18, 2011 10:34 AM To: Struts Users Mailing List Subject: Re: generate SQL Hibernate Query using session What does having joins have to do with not being able to map to your data model? Dave On Feb 17, 2011 8:43 PM, "Jerson John" wrote: > 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
Re: generate SQL Hibernate Query using session
What does having joins have to do with not being able to map to your data model? Dave On Feb 17, 2011 8:43 PM, "Jerson John" wrote: > 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 >
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