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