"HibernateException: Could not locate table which owns column [...] referenced in order-by mapping" in EAP 6
Issue
- Add
@OrderByto an association collection referencing a column of a parent entity type in aJOINEDinheritance hierarchy
@Entity
@Table(name = "Joined_Parent")
@Inheritance(strategy = InheritanceType.JOINED)
public class JoinedParent
{
@Id
@GeneratedValue
@Column(name = "id")
private Integer id;
@ManyToOne(cascade = {CascadeType.ALL})
@JoinColumn(name = "other_entity_id", nullable = false)
private OtherEntity otherEntity;
}
@Entity
@Table(name = "Joined_Child")
@PrimaryKeyJoinColumn(name = "id")
public class JoinedChild extends JoinedParent
{
}
@Entity
@Table(name = "Other_Entity")
public class OtherEntity
{
@OneToMany(cascade = CascadeType.ALL, mappedBy = "otherEntity", orphanRemoval = true)
@OrderBy("id ASC") // <-- reference to JoinedParent.id causes the error
private List<JoinedParent> items = new ArrayList<JoinedParent>();
}
- A
HibernateExceptionis raised while creating the entity manager factory
javax.persistence.PersistenceException: [PersistenceUnit: CaseManagement] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924)
...
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:4991)
at org.hibernate.persister.collection.AbstractCollectionPersister$StandardOrderByAliasResolver.resolveTableAlias(AbstractCollectionPersister.java:1941)
at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator$StandardOrderByTranslationImpl.injectAliases(OrderByFragmentTranslator.java:106)
at org.hibernate.persister.collection.AbstractCollectionPersister.getSQLOrderByString(AbstractCollectionPersister.java:747)
...
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 6
- Hibernate 4
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
