2013-10-07 105 views
0

,當我跑我的iBatis的插入命令,我收到此錯誤:的Java iBatis的缺少INTO關鍵字

DEBUG [main] - Returned connection 31746664 to pool. 
DEBUG [main] - Checked out connection 31746664 from pool. 
DEBUG [main] - {conn-100014} Connection 
DEBUG [main] - {conn-100014} Preparing Statement:   INSERT INTO PORTFOLIOS    (theme_id    , start_date    , portfolio_name    , amount    , index_cd    , model_cd    , last_rebalance    , months_between_rebalance   )   VALUES    (1    , SYSDATE    , ?    , ?    , ?    , ?    , SYSDATE    , ?)   RETURNING portfolio_id  
DEBUG [main] - {pstm-100015} Executing Statement:   INSERT INTO PORTFOLIOS    (theme_id    , start_date    , portfolio_name    , amount    , index_cd    , model_cd    , last_rebalance    , months_between_rebalance   )   VALUES    (1    , SYSDATE    , ?    , ?    , ?    , ?    , SYSDATE    , ?)   RETURNING portfolio_id  
DEBUG [main] - {pstm-100015} Parameters: [testPortfolio2New, 100000.0, null, null, 0] 
DEBUG [main] - {pstm-100015} Types: [java.lang.String, java.lang.Double, null, null, java.lang.Integer] 
com.ibatis.common.jdbc.exception.NestedSQLException: 
--- The error occurred in ObjectRelationalMapping.xml. 
--- The error occurred while applying a parameter map. 
--- Check the sectoranalysis.domain.insertPortfolio-InlineParameterMap. 
--- Check the statement (update failed). 
--- Cause: java.sql.SQLSyntaxErrorException: ORA-00925: missing INTO keyword 

在我的映射文件中的相關位是:

 <insert id="insertPortfolio" parameterClass="com.fimt.sectoranalysis.domain.portfolio.Portfolio"> 
     INSERT INTO PORTFOLIOS 
      (theme_id 
      , start_date 
      , portfolio_name 
      , amount 
      , index_cd 
      , model_cd 
      , last_rebalance 
      , months_between_rebalance 
      ) 
     VALUES 
      (1 
      , SYSDATE 
      , #name# 
      , #investment# 
      , #index.ticker# 
      , #model.modelId# 
      , SYSDATE 
      , #frequency#) 
     RETURNING portfolio_id 
    </insert> 

我不明白因爲INTO關鍵字非常清晰。爲什麼我的Oracle DB返回這個錯誤?

回答

0

的syntaxt是:

INSERT INTO (...) VALUES (...) RETURNING (...) INTO (...) 

在您的例子甲骨文抱怨,因爲它預計第二INTO關鍵字。 我會嘗試使用語句resultClass參數:

<statement id="insertPortfolio" parameterClass="com.fimt.sectoranalysis.domain.portfolio.Portfolio" resultClass="int"> 
... 
</statement> 

對於一些更多的例子,請參閱: Howto return ids on Inserts with Ibatis (with RETURNING keyword)