• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate query with criteria as an object

 
Gene Hilpert
Ranch Hand
Posts: 51
Eclipse IDE Hibernate Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been tiring to use the criteria to filter a query with an object.
Is this possible?

When I execute the query it brings back all Eventattendance not just the one
I'm query for.
When I query on some other field a String or Int the query works as I would expect.

I'm using hibernate3 with a derby database.




Thanks
 
Brett Maclean
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gene,

I'm not sure what your object model looks like, so this may or may not be relevant ;-)

It sounds as if you have an association within your Eventattendance class represented by another object and you want to query your results and restrict by some attribute in the associated class.

I've added an example below which hopefully is similar to your model. I have a User class {name, age, Address} and an Address class {house number, city, postcode} and the criteria query that I've added will find all Users that have User.name beginning with 'B' and User.Address.postcode beginning 'SE19' (both non-case sensitive)



Basically, you end up creating a criteria on User for the associated class (in this case Address) and then adding a Restriction on that Criteria to limit your Addresses to those that begin with the right postcode.

HTH
 
Gene Hilpert
Ranch Hand
Posts: 51
Eclipse IDE Hibernate Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help. The question was simple - all I wanted was the list of who attened an event.

But I worked around that problem.

But now I'm working on another problem that I thing your solution will work for

Thanks again.
 
Brett Maclean
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah I see ... oh well, glad the "solution" is of use for a future problem! :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic