Reputation: 745
when I execute the below native query :
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();
I found the below error
Local Exception Stack: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: ORA-00900: invalid SQL statement
Error Code: 0
but when I execute this query in oracle ,It run good
does hibernate support to run MERGE statement or not?
Upvotes: 0
Views: 2207
Reputation: 745
thanks @Jorge Campos
MERGE
is a DML statement so I must execute .executeUpdate()
not .getSingleResult()
Upvotes: 1