Hibernate: create HQL Query with Attribute values from Sets

I want to create a HQL Query that can access Attributes of a Set of spezified Objects, let me explain via a short example:

Class Organization

public class Organization ...{
    private int orgid;
    private Set<DomainValue> languages = new HashSet<language>(0);
    private Set<Address> adresses = new HashSet<Address>(0);
    ...
}

Class Address

public class Address  implements java.io.Serializable {
   private int addressId;
   private String city;
   private String postalCode;
   private String streetName;
   private String houseNumber;
   ...
}

Language

public class Orgunitlanguage  implements java.io.Serializable {
   private int orgLanguageId;
   private Orgunit orgunit;
   private Integer languageCd;
   ...
}

These examples are code snippets of working hibernate POJOs. So i have an organization that can have multiple addresses and languages.

I want the user to specify the search criteria, but limit them to one of each kind, so only one language, one postalcode etc.

lets say the user wants english organizations with a housenumber 22

so i would build a hql query like this:

"from organization o where o.languages.languageCd = 1 AND o.addresses.housenumber = 22"

Well and that dosen't work (illegal syntax) how do i access these Sets in the right way? Keep in mind i want to access a specific attribute and not just the whole object (which is really easy).

I can't seem to find a documentation that i understand so a little explaination would be nice.

Answers


Proper way to query on collections would be like this

from Organization o join o.languages l join o.addresses a where l.languageCd = 1 AND a.housenumber = 22

However, this query will return any organization that has at least one language with languageCd = 1 and at least one address with housenumber = 22. It will not filter out the languages and addresses that don't fit the criteria. Check this answer for a little more explanation on this.


Need Your Help

Using R with Apache & PHP

php apache r

Is there anyway to run R scripts through Apache and PHP? I would like to be able to pass variables from PHP to R.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.