在eclipselink中执行SELECT而不执行SELECT [英] Perform UPDATE without SELECT in eclipselink

查看:147
本文介绍了在eclipselink中执行SELECT而不执行SELECT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以(不编写自定义SQL)让Eclipselink信任我是否执行更新或在合并中插入,而不是执行选择,然后执行更新或插入?如果是这样,怎么办?

Is is possible (without writing custom SQL) to have Eclipselink trust me as to whether to perform an update or insert on a merge, rather than perform a select, then an update or insert? If so, how?

在我看来,我想使用瞬态标志和自定义if语句来确定该项是否已在数据库中,并指示eclipselink执行所需查询。我了解Hibernate将其作为update()和save()

In my mind I'd like to use a transient flag and a custom if statement to determine whether the item is already in the database or not, and instruct eclipselink to perform the query required. I understand Hibernate provides this as update() and save()

一些值得注意的点:


  • 我有大量对象要进行批合并,因此
    persist()不适合我(这些对象在
    库中不存在,除非它们

  • 由于要合并的对象太多,因此不太可能会有缓存命中,因此eclipselink无法确定它是否发送了它通过缓存进入之前

  • 由于要进入(在这种情况下,是非本地数据库中的)大量对象,所以SELECTs是一个问题,特别是考虑到我可以确定之前需要操作发生

  • 我真的不希望切换到休眠状态

  • I have a large amount of objects that are being batch-merged, as such persist() is not suitable for me (also the objects do not exist in the library except when they are passed in for the merge anyway)
  • Because there are so many objects being merged, it is unlikely that there will be any cache hits, so eclipselink has been unable to tell if its sent it in before via the cache
  • Because amount of objects going in (to a non-local database, in this case) the SELECTs are a problem, especially given I can tell which will be required before the operation occurs
  • I'd really rather not switch to Hibernate

谢谢。

推荐答案

您正在寻找的东西在EclipseLink中称为存在检查,可以使用@ExistenceChecking注释,如下所示:
http:// eclipse。 org / eclipselink / documentation / 2.4 / jpa / extensions / a_existencechecking.htm

What you are looking for is called existence checking in EclipseLink, and can be configured using the @ExistenceChecking annotation as described here: http://eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_existencechecking.htm

尝试指定@ExistenceChecking(ExistenceType.CHECK_CACHE),因为它指出check_cache是默认值,这是针对本机EclipseLink项目的。 JPA项目使用Check_Database作为默认值,以符合JPA规范,该规范要求合并调用在必要时合并到数据库中的数据中。使用check_cache将完全阻止EclipseLink进行查询,因此您可以根据自己的条件查询自己。但是,现有的对象将必须位于缓存中,否则,没有任何内容可以合并到其中,EclipseLink将必须执行插入操作。

Try specifying @ExistenceChecking(ExistenceType.CHECK_CACHE) as while it states that check_cache is the default,this is for Native EclipseLink projects. JPA projects use a Check_Database as the default to conform to the JPA specification requiring that merge calls merge into data from the database if necessary. Using the check_cache will prevent EclipseLink from querying at all, so you can query yourself based on your own criteria. Existing objects will be required to be in the cache though, otherwise there is nothing to merge into, and EclipseLink will have to perform an insert.

另一种选择是使用定制程序,用于定义每个类使用的DidExistQuery。这可以允许您重写checkEarlyReturn方法以根据需要执行以确定存在的方法。

Another option is to use a customizer to define the DoesExistQuery used for each class. This could allow you to override the checkEarlyReturn method to perform as needed to determine existence.

上述选项仍然使用JPA合并,因此仍然需要将现有数据合并到其中-因此仍然需要选择不在缓存中的现有对象。如果您所需要的只是一个更新所有类型的语句,它将更新对象或按原样插入对象,而不仅跟踪已更改的内容,则可以尝试查看本机EclipseLink功能,例如UnitOfWork api。使用((EntityManagerImpl)em.getDelegate())。getUnitOfWork()。updateObject(entity)之类的东西或使用UOW执行自己的UpdateObjectQuery可以避免选择现有对象,而只会发送更改。

The above options still use the JPA merge and so still require getting the existing data to merge into - so it will still require selects for existing objects not in the cache. If all you are after is an update all type statement that will update the object or insert the object as is, without tracking only what has changed, you might try looking at native EclipseLink functionality, such as the UnitOfWork api. Using something like ((EntityManagerImpl)em.getDelegate()).getUnitOfWork().updateObject(entity) or use the UOW execute your own UpdateObjectQuery would avoid the selects for existing objects, at the loss of only sending changes.

这篇关于在eclipselink中执行SELECT而不执行SELECT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆