但是,我得到以下信息: org.eclipse.persistence.exceptions.QueryException: Exception Description: Objects cannot be written during a UnitOfWork, they must be registered.Query: UpdateObjectQuery 我正以正确的方式来处理吗?如果是这样,我该如何纠正错误?谢谢解决方案感谢答案的作者这里,有效的解决方案如下,跟踪自己进入数据库的内容,其中"em"是eclipselink实体管理器: 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 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);}However, i get the following:org.eclipse.persistence.exceptions.QueryException: Exception Description: Objects cannot be written during a UnitOfWork, they must be registered.Query: UpdateObjectQueryAm 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:AbstractSession session = ((EntityManagerImpl) em.getDelegate()).getUnitOfWork().getParent();if (dbObj.getLastModifiedTime().isAfter(lastUpdated)){ if (dbObj.isInDB()) { session.updateObject(dbObj); } else { session.insertObject(dbObj); }} 这篇关于没有初始SELECT的eclipselink merge()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 22:08