java - Spring-data-jpa 剛保存的信息查找不到
問題描述
1 后臺結構后臺的結構是 SpringMVC, Spring, jpa(HibernateJpaDialect),DataSource(c3p0), Mysql(InnoBDB), transactionManager(JpaTransactionManager)。
2 問題環境@Transactional(value = 'transactionManager', isolation = Isolation.READ_UNCOMMITTED) public Object addScenicSpot(int tourGuideID, String jsonStr) {Djd_js entity = new Djd_js();try{ _setEntity(entity, jsonStr); entity.setDaoyouID(tourGuideID); jdjsDao.save(entity); int spotId = entity.getId(); //添加信息到消息隊列中try { Sender sender = new SenderImpl(); sender.getGPSFromBaiduAPI('jdjs', spotId, entity.getDizhi());} catch (InterruptedException e) { return false;} return spotId;}catch (Exception e){ return false;} }
以上是保存的部分,并把得到的 ID 發送到消息隊列中,下邊是消息隊列的處理部分
public boolean updateLngAndLat(MessageVo messageVo) {System.out.println('CreateTime--------'+messageVo.getCreateDate());System.out.println('Address--------'+messageVo.getContent());System.out.println('Id--------'+messageVo.getId());Djd_js entity = jdjsDao.findOne(messageVo.getId());System.out.println('entity-Address--------'+entity.getDizhi());、、運行到這里就直接卡住了,如果注釋掉查詢,其他的調用皆正常。Map<String, Object> result = LngAndLatUtil.getLngAndLat(((MessageVo) messageVo).getContent());System.out.println('result--------'+(int)result.get('result'));if (1 == (int)result.get('result')){ entity.setJingdu(Double.valueOf(result.get('lng').toString())); entity.setWeidu(Double.valueOf(result.get('lat').toString())); System.out.println('message-------------------------------'+'lng:'+Double.valueOf(result.get('lng').toString())+', lat:'+Double.valueOf(result.get('lat').toString())); jdjsDao.updateLngAndLatBySenciSpotID(messageVo.getId(), (Double) result.get('lng'), (Double) result.get('lat'));}else { System.out.println('message-------------------------------False');}return false; }3 問題描述
前端調用 addScenicSpot() 方法,會將信息保存到數據庫中,然后將保存之后的數據控中的ID發送到消息隊列中,然后訂閱者處理隊列中的信息,根據 ID 查詢到剛保存的信息,然后調用外部接口查詢到經緯度,并將得到的經緯度存儲到數據庫中。現在的問題是,保存信息正常,但是到了訂閱者處理這邊,根據得到的 ID 查找不到保存的信息。
4 猜測問題所在產生bug的原因是spring事務提交晚于消息隊列的生產消息,導致消息隊列消費消息時獲取到的數據不正確,靈感來自于這里:http://www.cnblogs.com/taocon...
問題解答
回答1:同步調用,改為異步調用?
@AsyncgetGPSFromBaiduAPI
回答2:已經解決了問題了,應用的這里的方法:http://www.cnblogs.com/taocon...
相關文章:
1. phpadmin的數據庫,可以設置自動變化時間的變量嗎?就是不需要接收時間數據,自動變化2. html5和Flash對抗是什么情況?3. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?4. html - 爬蟲時出現“DNS lookup failed”,打開網頁卻沒問題,這是什么情況?5. javascript - vue項目里的package.json6. ios - 為什么用WKWebView加載相同的html文本,有時展示的內容卻不一樣。7. angular.js - vue中類似于angular的ng-change的指令是?8. javascript - Ubuntu修改port后無法登陸9. boot2docker無法啟動10. mac里的docker如何命令行開啟呢?
