-->
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.  [ 6 posts ] 
Author Message
 Post subject: @OrderBy on an inherited property
PostPosted: Fri Mar 28, 2008 4:35 pm 
Newbie

Joined: Fri Mar 28, 2008 4:12 pm
Posts: 3
I try to order a set of objects on a property inherited from an abstract class. The parent class is annotated by a InheritanceType.TABLE_PER_CLASS strategy.

the generated sql shows something like this:

order by AbstractEntity.inheritedProperty desc

but there is no table corresponding to the parent abstract class...

Is there something i've missed?
Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 28, 2008 8:48 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
you should avoid abstract classes for entities, make the superclass concrete: all entities need to be instantiatable (that's why they also need a default constructor)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 06, 2008 12:10 pm 
Newbie

Joined: Fri Mar 28, 2008 4:12 pm
Posts: 3
thanks for your answer but removing the abstract nature of the class doesn't change anything, the exception is the same:

Code:
20:26:58 ERROR (org.hibernate.util.JDBCExceptionReporter.java:78)
          ERROR: missing FROM-clause entry for table "abstractentity"



Any idea?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 06, 2008 12:29 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
you should post the source of both entities and the HQL query to get better help.
Is the superclass an @Entity ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 3:51 pm 
Newbie

Joined: Fri Mar 28, 2008 4:12 pm
Posts: 3
ok i will try to explain my use case in more detail. So i have a parent class like this one (abstract or not it doesn't matter):

Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class AbstractEntity {
   (..)
   private String commonProperty;
   (..)
}


and two child classes:

Code:
@Entity
public class FirstEntity extends AbstractEntity {
   (..)
}


Code:
@Entity
public class SecondEntity extends AbstractEntity {
   (..)
   @OneToMany(mappedBy="secondEntity")
   @OrderBy("commonProperty desc")
   private Set<FirstEntity> firstEntities;
   (..)
}


When the collection is loaded in the SecondEntity, the following exception is fired:

Code:
Hibernate: select firstentity0_.commonProperty as commonProperty3_28_0_, firstentity0_.secondEntity_id as secondEntity1_33_0_ from firstentity firstentity0_ where firstentity0_.secondEntity_id=? order by AbstractEntity.commonProperty desc
21:06:01 ERROR (org.hibernate.util.JDBCExceptionReporter.java:78)
          ERROR: missing FROM-clause entry for table "abstractentity"


Top
 Profile  
 
 Post subject: Look on the following it might help
PostPosted: Mon Apr 07, 2008 5:14 pm 
Beginner
Beginner

Joined: Mon Apr 07, 2008 12:49 pm
Posts: 33
http://opensource.atlassian.com/projects/hibernate/browse/ANN-651

As a workaround please try the "subselect" fetching strategy (so instead of on join SQL) you will get 2 SQL statement (1 for the parent and the second for the ordered children).

This can be done using the Hibernate extension annotation @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.