• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Complex HQL Query

 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so I have the following classes.



Now I'm trying to write a query in order to select prop 3, prop 4, and whether or not there is a link between C and B(I don't need Class B, just whether it's null or not). I have the Name of Class C. I currently have a query like this.



But this returns the following error. Not sure why it changes the case, either.


I have it working with a Criteria, but I'd like to do it this way because I don't need the whole object.

Thanks.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ranch Hand,

If you use Criteria Than also you do not need to get the whole object if you are creating a Criterai Query and by using Projection Class you can get the required properties also.

Here is a simple way to get the results as List of object array containing the name property.

List results = session.createCriteria(A.class)
.setProjection( Projections.projectionList()
.add( Projections.property("name"), "Name" )
)
.add( Restrictions.eq("Name", "Your_Condition") )

Hope this will help you...
 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

afsar khan wrote:Dear Ranch Hand,

If you use Criteria Than also you do not need to get the whole object if you are creating a Criterai Query and by using Projection Class you can get the required properties also.

Here is a simple way to get the results as List of object array containing the name property.

List results = session.createCriteria(A.class)
.setProjection( Projections.projectionList()
.add( Projections.property("name"), "Name" )
)
.add( Restrictions.eq("Name", "Your_Condition") )

Hope this will help you...



Didn't know about the Projection class. I'll have to take a look.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic