Hello,
after trying myself for quite a while and searching for answers in here, i'm slowly getting desparate. I think my problem should be easy to solve:
I have 2 Entities, Person and Company, where Person has a non-lazy, null-able many-to-one association to Company. Now I want to list all Persons ordered by the name of their associated Company. The hard part is that some Persons have no associated Company and I have no clue how to get the correctly ordered results.
I already tried different queries:
Code:
SELECT p FROM PersonImpl AS p ORDER BY p.hibCompany.hibCompanyName
--> this lists only Persons where p.hibCompany is not null
Code:
SELECT p FROM PersonImpl AS p LEFT JOIN p.hibCompany ORDER BY p.hibCompany.hibCompanyName
--> this lists all Persons but not ordered correctly
Help would be very, very appreciated... ;-)
This is a code snippet of my 2 Entities:
Code:
/**
*
* @hibernate.joined-subclass
* table = "ACC_PERSON"
* @hibernate.joined-subclass-key
* column = "PK"
*/
public class PersonImpl extends AbstractAccount implements Person {
/**
* @hibernate.many-to-one
* column = "FK_COMPANY"
* not-null = "false"
* not-found = "ignore"
* lazy = "false"
* access = "field"
*/
private CompanyImpl hibCompany = null;
}
/**
* @hibernate.joined-subclass
* table = "ACC_COMPANY"
* @hibernate.joined-subclass-key
* column = "PK"
*/
public class CompanyImpl extends AbstractAccount implements Company {
/**
* @hibernate.property
* column = "COMPANY_NAME"
* not-null = "true"
* type = "string"
* access = "field"
*/
private String hibCompanyName = "";
/**
* @hibernate.set
* inverse = "true"
* cascade = "none"
* access = "field"
* @hibernate.key
* column = "FK_COMPANY"
* @hibernate.one-to-many
* class = "com.goelz.marketingsuite.account.person.PersonImpl"
*/
private Set hibEmployees = new HashSet();
}
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0.5
Mapping documents: see above
Name and version of the database you are using: MySQL 4.1