保存对象时休眠StaleObjectStateException

时间:2018-11-20 16:41:15

标签: hibernate

我有两个POJO班  1. Profile.java  2. Account.java  3. Event.java

现在我的代码在这里

try {
         String key = null;
          // By passing userId i'm getting Profile object
          Profile profile = xxxx(ProfileDAO.class)
              .findByAccountId(userId);
          key = profile.getAccount().getAccountSecretKey();
        } catch (Exception se) {
      }
      Event se = new Event();
      se.setId(event.getId());
      se.setType(event.getType());
      se.setUserId(userId);
      xxx(EventDAO.class).save(se);

在此阶段,我在实体帐户上收到StaleObjectStateException

stacktrace:org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.xxxxx.Account#309650]
    at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:2509)
    at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3228)
    at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3126)
    at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3456)
    at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:140)
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:369)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:287)
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:339)
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)
    at xxxxx.DAO.save(DAO.java:82)
    at  

任何想法,为什么帐户实体会失效。 感谢前进

0 个答案:

没有答案