0
當我執行下面的本地查詢:hibernate是否支持運行MERGE語句?
String sql="merge into omfx.OM_PART_LOOKUP toLookup\r\n" +
" using omfx.OM_PART_LOOKUP fromLookup\r\n" +
" on(\r\n" +
" toLookup.PROJECT_ID= "+toProjectID+" and \r\n" +
" fromLookup.PROJECT_ID= "+fromProjectId +" and \r\n" +
" toLookup.scope =0 and \r\n" +
" UPPER(toLookup.PN) = UPPER(fromLookup.PN) and\r\n" +
" UPPER(toLookup.MAN) = UPPER(fromLookup.MAN)\r\n" +
" )\r\n" +
" when matched then update \r\n" +
" set \r\n" +
" \r\n" +
" toLookup.SEPN = fromLookup.SEPN ,\r\n" +
" toLookup.SE_MAN_ID = fromLookup.SE_MAN_ID ,\r\n" +
" toLookup.COM_ID = fromLookup.COM_ID ,\r\n" +
" toLookup.SE_MAN_NAME = fromLookup.SE_MAN_NAME ,\r\n" +
" toLookup.PART_CATEGORY = fromLookup.PART_CATEGORY \r\n" +
" \r\n" +
" \r\n" +
" when NOT matched then \r\n" +
" insert (PN,MAN,SEPN, SE_MAN_ID, COM_ID,SE_MAN_NAME ,PART_CATEGORY ,INSERT_DATE,PROJECT_ID)\r\n" +
" values (fromLookup.PN,fromLookup.MAN,fromLookup.SEPN, fromLookup.SE_MAN_ID, fromLookup.COM_ID , fromLookup.SE_MAN_NAME ,fromLookup.PART_CATEGORY , SYSDATE,"+toProjectID+") where\r\n" +
" fromLookup.PROJECT_ID = "+fromProjectId+" and fromLookup.scope = 0\r\n" +
" ";
System.out.println("projectOperationsBean.mergeManLookup()::sql=="+sql);
em.createNativeQuery(sql).getSingleResult();
我發現下面的錯誤
本地異常堆棧: 異常[EclipseLink的-4002(Eclipse持久服務 - 2.4.2.v20130514-5956486) :org.eclipse.persistence.exceptions.DatabaseException 內部異常:值java.sql.SQLException:ORA-00900:無效的SQL語句
錯誤代碼:0
但是當我在oracle中執行這個查詢時,它運行良好
是否支持hibernate運行MERGE語句?
那是什麼都沒有做與休眠。您正在以錯誤的方式執行此查詢。首先從查詢字符串中刪除所有'\ r \ n'。其次,確保這些連接是正確的(通過這種做法的錯誤方式,您應該使用準備好的語句)。 –
另外,這是一個聲明,應該使用executeUpdate執行而不是getSingleResult –
@JorgeCampos:'\ r \ n'不是問題,Oracle可以毫無問題地處理這個問題。 –