I made my “Insert” query (which is native SQL) as a named sql query <sql-query> and when I ran it using
int records = SQLQuery .executeUpdate();
I got a following Exception
java.lang.UnsupportedOperationException: Update queries only supported through HQL
at org.hibernate.impl.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:753)
at com.fanniemae.fapt.mtm.domain.ref.common.TopMoversMappingLoader.main(TopMoversMappingLoader.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
Also if I try to put the query in <sql-insert> tag , than how will I invoke it , since this doesn’t allows “name” attribute to name this query ??
Do you know a work around for doing this ??
My insert query is very complicated and cannot be converted in to HQL
<sql-query name = "findTOP">
<![CDATA[
Insert into PREV_MARK_MAPG(FA_MTM_ID,FA_MTM_EFF_DT,FA_PREV_MTM_ID)
(
select * from (
select FA_MTM_ID,
FA_MTM_EFF_DT,
LAG(FA_MTM_ID) OVER (PARTITION BY SECU_CUSIP_ID ORDER BY FA_MTM_EFF_DT ASC) AS PREV_MTM_ID
FROM FA_MARK
WHERE FA_MTM_EFF_DT <= :effDate
and trd_stat_cd = :assetState
and SECU_CUSIP_ID in (
select SECU_CUSIP_ID from fa_mark
where fa_mtm_id in (
select FA_MTM_ID from FA_MARK where TRD_STAT_CD = :assetState and FA_MTM_EFF_DT between TRUNC(:effDate) AND LAST_DAY(:effDate)
minus
select FA_MTM_ID from PREV_MARK_MAPG where FA_MTM_EFF_DT between TRUNC(:effDate) AND LAST_DAY(:effDate)
)
)
) where FA_MTM_EFF_DT between TRUNC(:effDate) AND LAST_DAY(:effDate)
)
]]>
</sql-query>
|