没有初始SELECT的eclipselink merge() [英] eclipselink merge() without initial SELECT
问题描述
我正在尝试使用eclipselink执行merge(entity)
,并且我想指示eclipse是更新还是插入,因此它不必执行初始的选择查询.多亏了这个问题所取得的进步,我有以下几点:>
但是,我得到以下信息:
org.eclipse.persistence.exceptions.QueryException: Exception Description: Objects cannot be written during a UnitOfWork, they must be registered. Query: UpdateObjectQuery
我正以正确的方式来处理吗?如果是这样,我该如何纠正错误?
谢谢
感谢答案的作者
I am trying to perform a However, i get the following: org.eclipse.persistence.exceptions.QueryException:
Exception Description: Objects cannot be written during a UnitOfWork, they must be registered.
Query: UpdateObjectQuery Am I approaching this the correct way? If so, how can I correct the error? Thanks 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: 这篇关于没有初始SELECT的eclipselink merge()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!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 perform the initial select query. Thanks to the progress made in this question, I have the following:UnitOfWorkImpl uow = (UnitOfWorkImpl) ((EntityManagerImpl) em.getDelegate()).getUnitOfWork();
if (dbObj.isInDB())
{
uow.updateObject(dbObj);
}
else
{
uow.insertObject(dbObj);
}
AbstractSession session = ((EntityManagerImpl) em.getDelegate()).getUnitOfWork().getParent();
if (dbObj.getLastModifiedTime().isAfter(lastUpdated))
{
if (dbObj.isInDB())
{
session.updateObject(dbObj);
}
else
{
session.insertObject(dbObj);
}
}