@OrderBy with a target property mapped to a @SecondaryTable.

Description

If the target property of an @OrderBy annotation is mapped to a SecondaryTable, the SQL select fails as it generates the order by clause using the alias of the primary table.

This, if we have a mapping such as the following:

@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name ="store_id")
@OrderBy(value = "displaySequence")
private Set<Product> products;

When the 'displaySequence' field of entity Product (table = "products") is mapped to a secondary table, the SQL order by is issued against "products" rather than this secondary table.

A simple standalone test case is available at the below. Simply run the test case and the issue can be seen from the generated SQL.

https://github.com/alanhay/hibernate-bug-2

Environment

Tested on SqlServer 2008, MySQL, HSQLDB

Assignee

Unassigned

Reporter

Alan Hay

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure