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

Description

If the target property of a @MapKey annotation is mapped to a SecondaryTable, the SQL select fails as it attempts to query for the map key against the Primary table.

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

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "stores_products", joinColumns = @JoinColumn(name = "store_id"), inverseJoinColumns = @JoinColumn(name = "product_id"))
@MapKey(name = "category")
private Map<String, Product> products;

When the 'category' field of entity Product (table = "products") is mapped to a secondary table, the SQL select 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-1

Environment

Tested on HSQLDB, MySQL, SQLServer 2008.

Assignee

Unassigned

Reporter

Alan Hay

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure