7
假設我有一個實體MyEntity
,它具有基於公式的屬性fmlaProp
。現在說我創造一個標準:休眠 - 按公式屬性排序條件
s.createCriteria(MyEntity.class)
.setProjection(
Projections.distinct(
Projections.property("fmlaProp")))
.addOrder(Order.asc("fmlaProp"));
在這種情況下,我得到了下面的SQL
:
SELECT DISTINCT fmlaProp-sql FROM MY_ENTITY_TABLE ORDER BY fmlaProp-sql
這給甲骨文說,訂單被表達是錯誤的非選擇。然後我嘗試了以下標準:
s.createCriteria(MyEntity.class)
.setProjection(
Projections.distinct(
Projections.alias(
Projections.property("fmlaProp"),
"alias1"))
.addOrder(Order.asc("alias1"));
它生成「order by alias1」,它工作正常。但它有點醜 - 代碼必須「知道」那些公式屬性,這違反了「一次寫入」的原則。對此有何想法或建議?先謝謝你。
什麼是'-sql'部分? – cherouvim