That depends on how you have mapped the associations between the three entities. I am going to assume that you have not mapped the associations between the entities at all. That is, there is no mapping for the one-to-one assocation between User and Profile, and there is no mapping for the one-to-many assocation between User and Company.
I expect the query you want will look something like this:
Code:
select user, profile
from User as user, Company as company, Profile as profile
where user.uid = profile.uid and company.uid = user.uid and company.cid = ?
This query will return a list of Object[]. Each Object[] will be of size 2. Index 0 will retrieve the User, 1 the Profile.
If you have mapped the associations then the query will be simplier. With the associations mapped your classes will probably look something like:
Code:
public class User {
...
public Profile getProfile() {
....
public Set<Company> getCompanies() {
...
}
public class Company {
...
public User getUser() {
....
}
In this case the query will be something like:
Code:
select user
from User as user inner join user.companies as company where company.cid = ?
To get access the profile assocated with the user you can simply call user.getProfile().
For more information on mapping one-to-one and one-to-many assocations have a look at: [url]
http://www.hibernate.org/hib_docs/v3/re ... n-onetoone[/url] and
http://www.hibernate.org/hib_docs/v3/reference/en/html/collections.html
For more information on HQL have a look at:
http://www.hibernate.org/hib_docs/v3/reference/en/html/queryhql.html