場(chǎng)景時(shí)在SSH2下的Service層。
某service中
java
... // 查詢事件模板 CommonEvent event = commonEventDao.find(code); // 模版內(nèi)容是"${name}登錄" String template = event.getTemplate(); template = template.replaceAll("\\$\\{name\\}", "admin"); event.setTemplate(template); // 其他service的調(diào)用 ...
上邊DAO的查詢:
java
public CommonEvent find(String code) { return (CommonEvent) sessionFactory0.getCurrentSession().get(CommonEvent.class, code); }
然后service結(jié)束后,數(shù)據(jù)庫(kù)中的event紀(jì)錄中的template字段從 ${name}登錄
變成了 admin登錄
,原因在哪里呢?
如果在find查詢時(shí)使用session.evict(event)將該對(duì)象逐出,則不會(huì)有臟寫的問(wèn)題。
如果不使用evict方法該怎么處理?
擁有18年軟件開(kāi)發(fā)和IT教學(xué)經(jīng)驗(yàn)。曾任多家上市公司技術(shù)總監(jiān)、架構(gòu)師、項(xiàng)目經(jīng)理、高級(jí)軟件工程師等職務(wù)。 網(wǎng)絡(luò)人氣名人講師,...
New a CommonEvent type object event2, copy the attribute value of the event, and put the content after repalceAll into event2. It should be that in the current logic code, the event is still persistent, so after the transaction is finally submitted, the content of the event is also updated to the database.