2
我有兩個postgreSQL表首選項,date_etl和preference_date_etl存儲它們的映射。休眠在同一個表上使用多個聯接
preference_date_etl的Hibernate映射:
<hibernate-mapping>
<class name="com..bla.bla.PreferenceDateETL"
table="preference_date_etl">
<id name="id" column="id" unsaved-value="null">
<generator class="sequence">
<param name="sequence">
<![CDATA[preference_date_etl_id_seq]]>
</param>
</generator>
</id>
...things....
</class>
</hibernate-mapping>
所以,現在當我執行一個HQL喜歡:
select distinct pd.preference from PreferenceDateETL pd where pd.corporation.id=:corporationId and pd.preference.employee.deleted=false and pd.deleted=false and pd.preference.deleted=false and pd.dateETL.localDate>=:startDM and pd.dateETL.localDate<=:endDM and pd.preference.approvalStatus!=:approvalStatus order by pd.preference.dateCreated
轉換爲SQL:
select
distinct preference1_.id as id1_76_,
....things...
from
preference_date_etl preference0_
inner join
preference preference1_
on preference0_.preference_id=preference1_.id cross
join
preference preference2_ cross
join
employee employee3_ cross
join
date_etl dateetl5_
where
...things...
order by
preference2_.date_created
問題:preference2_.date_created
在ORDER BY子句不在選擇列表中,因此例外SELECT DISTINCT, ORDER BY expressions must appear in select list
。
問題:爲什麼在同一個表上使用兩個連接INNER AND CROSS來休眠。如果在ORDER BY列表中有preference1_.date_created
那麼一切都會很好。想法?
只是要清楚 - 這是偏好和date_etl之間的多對多關係?不是一對一的? – Hedley 2014-08-28 17:08:22