Adding a collection of entities that use the inheritance strategy JOINED and adding an order by to the collection causes the following exception:
Caused by: org.hibernate.HibernateException: Could not locate table which owns column [id] referenced in order-by mapping
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.determineTableNumberForColumn(JoinedSubclassEntityPersister.java:854)
at org.hibernate.persister.entity.AbstractEntityPersister.getTableAliasForColumn(AbstractEntityPersister.java:4865)
at org.hibernate.persister.collection.AbstractCollectionPersister$StandardOrderByAliasResolver.resolveTableAlias(AbstractCollectionPersister.java:1930)
at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator$StandardOrderByTranslationImpl.injectAliases(OrderByFragmentTranslator.java:106)
at org.hibernate.persister.collection.AbstractCollectionPersister.getSQLOrderByString(AbstractCollectionPersister.java:751)
at org.hibernate.loader.JoinWalker.orderBy(JoinWalker.java:910)
at org.hibernate.loader.JoinWalker.orderBy(JoinWalker.java:822)
at org.hibernate.loader.AbstractEntityJoinWalker.initStatementString(AbstractEntityJoinWalker.java:123)
at org.hibernate.loader.AbstractEntityJoinWalker.initStatementString(AbstractEntityJoinWalker.java:108)
at org.hibernate.loader.AbstractEntityJoinWalker.initAll(AbstractEntityJoinWalker.java:90)
at org.hibernate.loader.AbstractEntityJoinWalker.initAll(AbstractEntityJoinWalker.java:77)
at org.hibernate.loader.entity.CascadeEntityJoinWalker.<init>(CascadeEntityJoinWalker.java:51)
at org.hibernate.loader.entity.CascadeEntityLoader.<init>(CascadeEntityLoader.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:3785)
at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:3722)
at org.hibernate.persister.entity.SingleTableEntityPersister.postInstantiate(SingleTableEntityPersister.java:1018)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:457)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
... 9 more
The following code snippets demonstrate the problem:
@Entity
@Table(name = "Joined_Child")
@PrimaryKeyJoinColumn(name = "id")
public class JoinedChild
extends JoinedParent
{
}
OtherEntity.java
@Entity
@Table(name = "Other_Entity")
public class OtherEntity
{
@OneToMany(cascade = CascadeType.ALL, mappedBy = "otherEntity", orphanRemoval = true)
@OrderBy("id ASC") // <-- this causes the error
private List<JoinedParent> items = new ArrayList<JoinedParent>();
}
From what I can tell from debugging through the code. It looks as if the @Id of the joined parent classes is not being added to the "available" columns for the subclasses.
I would be happy to add a test case for this if someone could point me to a simple template for doing so.
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira