0

I am having following method

    @Transactional
@JamonMonitored(type = MonitorType.DAO, tag = "name=JpaKeywordDao,method=save")
public void save(List<KeywordEntity> keywords) {
    Query updateBidStmt = entityManager.createNativeQuery(SQL_UPDATE_KEYWORD_BIDS_WITH_OPTIONAL_BID);
    for (KeywordEntity keyword : keywords) {
        updateBidStmt.setParameter(PARAM_INTERNAL_KEYWORD_ID, keyword.getInternalId());
        updateBidStmt.setParameter(PARAM_BROAD_MATCH_BID, keyword.getBroadMatchBid() == null ? -1 : keyword.getBroadMatchBid());
        updateBidStmt.setParameter(PARAM_CONTENT_MATCH_BID, keyword.getContentMatchBid() == null ? -1 : keyword.getContentMatchBid());
        updateBidStmt.setParameter(PARAM_EXACT_MATCH_BID, keyword.getExactMatchBid() == null ? -1 : keyword.getExactMatchBid());
        updateBidStmt.setParameter(PARAM_PHRASE_MATCH_BID, keyword.getPhraseMatchBid() == null ? -1 : keyword.getPhraseMatchBid());
        updateBidStmt.executeUpdate();
    }
}

I guess this method executes update 1 by 1. I want to do this in bulk as it is putting load on server.

Please help.

user3529381
  • 43
  • 1
  • 3
  • 9
  • That depends - have you actually _looked_ at the generated SQL? For example, with MySQL - [this might be of interest](http://stackoverflow.com/questions/26307760/mysql-and-jdbc-with-rewritebatchedstatements-true). – Boris the Spider Nov 09 '14 at 17:26
  • protected static final String SQL_UPDATE_KEYWORD_BIDS_WITH_OPTIONAL_BID = "UPDATE {h-schema}MSN_KEYWORDS set " + " BROAD_MATCH_AMT = nullif(:broadMatchBid, -1), " + " CONTENT_MATCH_AMT = nullif(:contentMatchBid, -1)," + " EXACT_MATCH_AMT = nullif(:exactMatchBid, -1)," + " PHRASE_MATCH_AMT = nullif(:phraseMatchBid, -1), " + " UPDATE_DT = SYSDATE " + "where OBJECT_ID = :internalKeywordId"; This is the SQL. – user3529381 Nov 10 '14 at 05:40

0 Answers0