These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: @OrderBy added to wrong table in inheritance relationship
PostPosted: Wed Dec 27, 2006 11:06 am 
Newbie

Joined: Wed Dec 27, 2006 10:38 am
Posts: 3
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!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 11:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is probably a bug, please attach a minimal runnable test case to JIRA, I'll need to have a look, or even better try and provide a patch :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 11:23 am 
Newbie

Joined: Wed Dec 27, 2006 10:38 am
Posts: 3
emmanuel wrote:
This is probably a bug, please attach a minimal runnable test case to JIRA, I'll need to have a look, or even better try and provide a patch :-)


Thanks! :)

I'll try to make a simple testcase that hopefully reproduces the problem. I'll keep you informed here once it's done.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 2:58 pm 
Newbie

Joined: Wed Dec 27, 2006 10:38 am
Posts: 3
Hi Emmanuel!

Martijn (friend I work with) just filed the bug along with a testcase, it is reproducable. See http://opensource.atlassian.com/project ... se/ANN-516

Hope you can fix it! :)


Top
 Profile  
 
 Post subject: Re: @OrderBy added to wrong table in inheritance relationship
PostPosted: Tue Nov 15, 2011 6:22 am 
Newbie

Joined: Tue Nov 15, 2011 5:57 am
Posts: 1
Hi,

I see the JIRA ticket was fixed (in a hacked way :), but now I have the same problem, however via double inheritance.

In my case is:

Code:
@MappedSuperclass
public abstract class Entity {

        @Column(name = "created_on", updatable = false)
   @Temporal(TemporalType.TIMESTAMP)
   protected Date   created;

        @PrePersist
   protected void onCreate() {
      created = new Date();
   }
}

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class File extends Entity {
        .....
}

@Entity
@Table(name = "concrete_file")
public class ConreteFile extends File {
        .....
}


And then I have another inheritance tree:

Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "department")
public abstract class Department extends Entity {

        @OneToMany(...)
        @OrderBy("created DESC")
   protected List<ConcreteFile>   files;

}


Unfortunately the @OrderBy will fail as it is complaining about non existing column "created".
Is it even possible to refer to property inherited from abstract class within another abstract class?

Thanks a lot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.