Hi,
Hibernate version: 3.2.1 GA, same for annotations
Mapping documents: None, annotations
Full stack trace of any exception that occurs:
java.sql.SQLException: ORA-00904: "ORGANISATI0_"."FIRST_NAME": invalid identifier
Name and version of the database you are using: Oracle 10G REL 2
The generated SQL (show_sql=true):
select organisati0_.fk_id_organisation as fk3_2_
, organisati0_.id_organisation_user as id1_2_
, organisati0_.id_organisation_user as id1_1_1_
, organisati0_1_.fk_id_account as fk7_1_1_
, organisati0_1_.email as email1_1_
, organisati0_1_.first_name as first3_1_1_
, organisati0_1_.last_name as last4_1_1_
, organisati0_.fk_id_organisation as fk3_2_1_
from ORGANISATION_USER organisati0_,
PERSON organisati0_1_
where organisati0_1_.fk_id_account=account1_.id_account
and organisati0_.id_organisation_user=organisati0_1_.id_person
and organisati0_.fk_id_organisation=1
order by organisati0_.first_name asc -- NOTE this line, its done on the user instead of person
Debug level Hibernate log excerpt: N/A
The template above provides the details. Let's make a few things clear first however.
I am using ejb3 annotations for mapping the relations between POJO's. The annotation @OrderBy (ejb3) works fine on normal relationships. But in above statement I have a parent-child relationship as follows:
Person
OrganisationUser (extends Person)
Organisation has * OrganisationUsers
In organisation the following method is annotated:
Code:
@OneToMany (mappedBy="organisation",
fetch=FetchType.LAZY,
cascade={CascadeType.PERSIST,CascadeType.MERGE})
@OrderBy (value="firstName")
public Set<OrganisationUser> getOrganisationUsers() {
return organisationUsers;
}
On the other side user maps organisation as follows:
Code:
@ManyToOne (cascade={CascadeType.PERSIST,CascadeType.MERGE})
@JoinColumn (name="fk_id_organisation",nullable=false)
public Organisation getOrganisation() {
return organisation;
}
The inheritance between Person and OrganisationUser is mapped using:
Code:
@Entity
@Inheritance (strategy=InheritanceType.JOINED)
@Table (name="PERSON")
public class Person ...
@Entity
@PrimaryKeyJoinColumn (name="id_organisation_user")
@Table (name="ORGANISATION_USER")
public class OrganisationUser extends Person ...
The @OrderBy (value="firstName") at getOrganisationUsers() is incorrectly performed on the ORGANISATION_USER table (see query) instead of its parent Person (who has the firstName property).
Is this correct behavior, am I doing something wrong, or might this be a bug? If so, how and where should I file it?
Thanks for your time!