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. javascript - webpack 報錯 新人 求解2. windows-7 - Wamp集成環境Apache無法啟動3. node.js - 跑antd的的模板例子!想修改端口,怎么修改呢!!(里面好像用了什么dora插件!!!)4. angular.js - angular做點擊購買時的遮罩層5. nginx 80端口反向代理多個域名,怎樣隱藏端口的?6. android - NavigationView 的側滑菜單中如何保存新增項(通過程序添加)7. angular.js - 關于ng-model和ng-bind的疑問8. 有大佬知道這種接口文件怎么使用嗎?9. 希望講講異常處理10. 求一個PHP編程碼、。
