我已经关闭了hibernate会话,但它给我的警告说会话没有关闭,可能是它的内存泄漏?

时间:2018-04-09 12:24:27

标签: java hibernate session java-ee resources

我在使用eclipse内存泄漏分析器的hibernate应用程序中发现了内存泄漏。我正在做一切正确但在以下函数会话的返回语句中得到错误可能不会被关闭。 这是我的代码

FROM `users` `u`
    LEFT JOIN `devices` `d` ON `u`.`id` = `d`.`user_id` and `d`.`expert_id` LIKE '%'
    LEFT JOIN `owners` `o` ON `d`.`comm_id`=`o`.`id`
    LEFT JOIN `experts` `e` ON `d`.`expert_id`=`e`.`id`
    LEFT JOIN `geography` `g` ON `u`.`voivod`=`g`.`id`
WHERE  `u`.`id` LIKE 3332 AND
       `u`.`voivod` LIKE '%' AND `u`.`city` LIKE "%" AND `u`.`status` LIKE '%'

在return语句中,我收到错误public static boolean insertLocalAccount() { boolean isInsertedSuccefully = false; Logger logger = Logger.getLogger("Sync_FILE_LOGGER"); logger.info("This is SyncLocalInsert --> insertLocalAccount function"); Session clientSession = HibernateUtilLocal.getSession(); @SuppressWarnings("unchecked") List<Account> accountList = clientSession.createCriteria(Account.class) .add(Restrictions.eq("isUploaded", false)) .setMaxResults(100) .list(); if(accountList.size() > 0){ String json = new ConnectionUtil().ConvertStringToJSON(accountList); String flag = new ConnectionUtil().CallWebService("saveAccountData", json); if(flag.trim().equals("true")){ Transaction clinetTx = clientSession.beginTransaction(); try { int i = 0; for (Account account : accountList) { account.setIsUploaded(true); clientSession.merge(account); if (i % 50 == 0) { clientSession.flush(); clientSession.clear(); } i++; } clinetTx.commit(); isInsertedSuccefully = true; } catch (Exception e) { e.printStackTrace(); if (clinetTx != null) { clinetTx.rollback(); } Exception e1 = new Exception(e); logger.error("This is an error log entry SyncLocalInsert --> insertLocalAccount function ", e1); isInsertedSuccefully = false; } finally { if (clientSession != null) { HibernateUtilLocal.closeSession(); } } } } return isInsertedSuccefully; }

HibernateUtilLocal.java

Potential resource leak: clientSession may not be closed at this location

}

0 个答案:

没有答案