Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Complex HQL Query

 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • 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.
 
afsar khan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic