eclipselink提示,用于setter更新 [英] eclipselink hints for setter updates

查看:111
本文介绍了eclipselink提示,用于setter更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临的实际问题是无论缓存内容如何,​​都可以强制执行eclipselink更新.当前,如果新的更新具有与缓存中相同的值,则eclipselink不会创建新的更新语句.我不想使用refresh属性( )在持久性xml中.

The actual problem I am facing is to be able to force a eclipselink update irrespective of the content of the cache. Currently eclipselink doesn't create new update statements if the new update has the same value as in the cache. I don't want to use the refresh property( ) in the persistence xml.

我正在寻找一种解决方案,可以指定要更新的实体不使用缓存中的值.

I am looking for a solution where I can specify to the entity being update not to use the values in the cache.

EntityManager em=getEntityManager();
    EntityTransaction t = em.getTransaction();

    t.begin();

    Ticket ticket = get(ticketId);

    if(ticket == null) {
        return null;
    }

    ticket.setState(status);

    em.persist(ticket);
    t.commit();

如果我将上述update(setState方法)更改为sql查询,则查询对象可以执行setHint的选项,我们可以在其中提及setHint(QueryHints.CACHE_USAGE,CacheUsage.DoNotCheckCache).我也无法执行此操作,因为使用了大量此类更新.

If I change the above update(setState method) to a sql query then the query object has an option to do a setHint where we can mention the setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache). I cannot do this either as there are a lot of such updates used.

在以上代码段中,更新是使用setter方法进行的,在这种情况下,我们如何指定忽略缓存的提示?还是有其他方法可以使用setter对象进行力更新?

In the above snippet the update is happening using a setter method, in this scenario how do we specify a hint to ignore cache? Or is there any other way to do the force updates using the setter object?

 My problem is similar to this : http://www.eclipse.org/forums/index.php/m/660750/

先谢谢您.

推荐答案

使用DescriptorCustomizer,我可以覆盖从eclipselink生成的更新sql.以下是示例代码段.但这需要大量的代码更改.如果您中有人知道通过使用一些批注或更改配置文件来减少干扰的方法,请告诉我.

Using the DescriptorCustomizer I was able to override the update sql generated from the eclipselink. Below is the sample snipppet. But this needs a lot of code changes. If any one of you know a way to do this less intrusively by using some annotations or some configruation file changes please let me know.

import org.eclipse.persistence.config.DescriptorCustomizer;
import org.eclipse.persistence.descriptors.ClassDescriptor;

public class TicketCustomizer implements DescriptorCustomizer{
     public void customize(ClassDescriptor descriptor) {

     String sqlString="update Ticket set DESCRIPTION = #DESCRIPTION, CUSTOMERNAME=#CUSTOMERNAME ,STATE= #STATE where ID = #ID and PRODUCTID= #PRODUCTID" ;

         descriptor.getQueryManager().setUpdateSQLString(sqlString);
        }

}

然后为Entity类定义定制器:

Then define the Customizer for the Entity class:

@Entity
@Customizer(com.oracle.ticketsystem.customizer.TicketCustomizer.class)
public class Ticket implements Serializable {......}

这篇关于eclipselink提示,用于setter更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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