0
工作我有四個外鍵的表和圖像:NonUniqueDiscoveredSqlAliasException爲MySQL查詢在phpMyAdmin
+--------------+--------------+---------------------+---------------------+-------+
| dataset_1_fk | dataset_2_fk | attribute_type_1_fk | attribute_type_2_fk | image |
+--------------+--------------+---------------------+---------------------+-------+
使用兩個數據集的名字,我想選擇兩個屬性的圖像和名稱。這裏是我的Hibernate代碼:
org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [name] during auto-discovery of a native-sql query
at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:594)
但是,當我發出從phpMyAdmin的相同的查詢,它工作正常:
HibernateUtil
.getCurrentSession()
.createSQLQuery(
"SELECT ddm.image, at1.name, at2.name " +
"FROM dataset_dataset_matrices AS ddm " +
" JOIN dataset AS d1 ON d1.id = ddm.dataset_1_fk " +
" JOIN dataset AS d2 ON d2.id = ddm.dataset_2_fk " +
" JOIN attribute_type AS at1 ON at1.id = ddm.attribute_type_1_fk " +
" JOIN attribute_type AS at2 ON at2.id = ddm.attribute_type_2_fk " +
"WHERE d1.name = :dataset_1 AND d2.name = :dataset_2"
)
.setString("dataset_1", dataset_1)
.setString("dataset_2", dataset_2)
.list();
當它執行我收到此錯誤。另外,如果我從SELECT
語句中刪除at1.name
或at2.name
,則查詢在Hibernate中起作用。我怎樣才能解決這個問題?