abcbuzhiming
abcbuzhiming
2013-08-15 18:42

把业务逻辑从Action层移到Service层遇到的麻烦,求解

  • spring
  • hibernate

以前一直把逻辑全部放在action层的,service只是从被action调用,从daoInterfaceFactory里获得dao然后用dao执行crud,最近一直听别人说service层离数据库更近一点,于是开始尝试把业务逻辑放在service,但是出现了一个让我意想不到的问题,在service层里,我需要把数据库里的数据取出和外部传来的一个vo里的数据作比较,符合条件就更新这个vo,我把vo的id赋值为和数据库取出的那个对象的id一样的数值,然后用hibernate的templte里的update方法,结果hibernate报异常说我有两个id重复的对象

org.apache.struts2.dispatcher.Dispatcher:38 - Exception occurred during processing request: a different object with the same identifier value was already associated with the session: [com.gameo.vo.GameChartsSingle#1]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.gameo.vo.GameChartsSingle#1]

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答