eclipselink merge() without initial SELECT

后端 未结 1 576
挽巷
挽巷 2021-01-23 06:36

I am trying to perform a merge(entity) using eclipselink, and I would like to indicate to eclipse if that will be an update or insert, so it does not have to perfor

相关标签:
1条回答
  • 2021-01-23 07:13

    Thanks to the author of the answer here, the working solution is as follows, keeping track myself of what has gone into the DB, where 'em' is the eclipselink entity manager:

    AbstractSession session = ((EntityManagerImpl) em.getDelegate()).getUnitOfWork().getParent();
    if (dbObj.getLastModifiedTime().isAfter(lastUpdated))
    {
        if (dbObj.isInDB())
        {
            session.updateObject(dbObj);
        }
        else
        {
            session.insertObject(dbObj);
        }
    }
    

    0 讨论(0)
提交回复
热议问题