我在我的DAO類中有下面的方法。在Tridion 2011中無法找到Hibernate查詢中的命名參數
public PublishAction findbyLatestPublishedDate(int tcmURI,int pubID) throws StorageException
{
log.info("Entering Method: JPAPublishActionDAO.PublishAction.findbyLatestPublishedDate");
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("select pa from PublishAction pa where pa.id in(select pb.id from PublishAction pb where pb.ITEM_REFERENCE_ID=:tcmURI and pb.PUBLICATION_ID=:pubID and rownum <= 1 order by pb.LAST_PUBLISHED_DATE desc)");
Map<String, Object> queryParams = new HashMap<String, Object>();
queryParams.put("ITEM_REFERENCE_ID", tcmURI);
queryParams.put("PUBLICATION_ID", pubID);
log.debug("JPAPublishActionDAO findbyLatestPublishedDate -> queryBuilder- "+ queryBuilder.toString());
return executeQuerySingleResult(queryBuilder.toString(), queryParams);
}
這是給下面的錯誤:
2013-01-16 12:17:01,381 ERROR DeployPipelineExecutor - Original stacktrace for transaction: tcm:0-5607662-66560
java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: could not locate named parameter [PUBLICATION_ID]
這是查詢內部在我的日誌受HQL產生:
2013-01-16 12:17:01,365 DEBUG QueryTranslatorImpl - SQL: select publishact0_.ID as ID66_, publishact0_.ITEM_REFERENCE_ID as ITEM2_66_, publishact0_.LAST_PUBLISHED_DATE as LAST3_66_, publishact0_.PUBLICATION_ID as PUBLICAT4_66_, publishact0_.ACTION as ACTION66_, publishact0_.FLAG as FLAG66_, publishact0_.ITEM_TYPE as ITEM7_66_, publishact0_.SCHEMA_ID as SCHEMA8_66_, publishact0_.URL as URL66_ from AUTN_ITEMS publishact0_ where publishact0_.ID in (select publishact1_.ID from AUTN_ITEMS publishact1_ where publishact1_.ITEM_REFERENCE_ID=? and publishact1_.PUBLICATION_ID=? and rownum<=1 order by publishact1_.LAST_PUBLISHED_DATE desc)
我可以看到PUBLICATION_ID列在我的實體存在,以及如在我的SQL表中。
請建議。
嗨丹尼爾,感謝您的回覆現在我得到wiered錯誤的訂單子句說com.microsoft.sqlserver.jdbc.SQLServerException:在視圖,內聯函數,派生表,子查詢和公用表ORDER BY子句無效表達式,除非TOP或FOR XML也被指定。 –
這並不像看起來那麼簡單。解決它的最簡單方法是將查詢分割爲2:「從PublishAction pb中選擇pb.id,其中pb.tcmuri =:tcmURI和pb.publicationId =:pubID order by pb.lastPublishDate desc」and seconde one「select pa從PublishAction pa where pa.id =:myId「,其中myId從第一個查詢開始。 –
嗨你能否請更新你的ansewer中的示例代碼,因爲它不太清楚你的意見 –