Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Caching JPA2.0缓存和插入查询_Caching_Jpa_Entity_On Duplicate Key - Fatal编程技术网

Caching JPA2.0缓存和插入查询

Caching JPA2.0缓存和插入查询,caching,jpa,entity,on-duplicate-key,Caching,Jpa,Entity,On Duplicate Key,问题描述 该应用程序升级为使用Eclipselink作为JPA2.0提供程序,并运行到一系列重复密钥异常。应用程序接收到巨大的流量,并使用实体进行大量的数据库插入 最近,该应用程序已升级为使用EclipseLink JPA2.0作为JPA提供商。在此之前,该应用程序使用的是JPA1.0。下面列出的实体是为JPA1.0编写的,我们继续在JPA2.0中使用它。但是我们正在经历许多重复的密钥异常 我在一篇文章中读到JPA1.0不提供共享缓存,但Eclipselink默认提供共享缓存 问题: *1*插入

问题描述

该应用程序升级为使用Eclipselink作为JPA2.0提供程序,并运行到一系列重复密钥异常。应用程序接收到巨大的流量,并使用实体进行大量的数据库插入

最近,该应用程序已升级为使用EclipseLink JPA2.0作为JPA提供商。在此之前,该应用程序使用的是JPA1.0。下面列出的实体是为JPA1.0编写的,我们继续在JPA2.0中使用它。但是我们正在经历许多重复的密钥异常

我在一篇文章中读到JPA1.0不提供共享缓存,但Eclipselink默认提供共享缓存

问题: *1*插入查询如何在共享缓存模式下工作。JPA框架正在缓存insert查询,导致重复密钥异常。我问这个问题是因为没有JPA1.0中的共享缓存模式,这个实体类可以正常工作

2由于当前应用程序升级为使用JPA 2.0,我应该在实体上设置共享缓存模式吗

@Cache(isolation=CacheIsolationType.ISOLATED, expiry=0, alwaysRefresh=true)
以适应JPA2.0版本。这样行吗? 我更感兴趣的是在JPA2.0中缓存insert查询的方式,并且以某种方式导致重复的密钥异常

我们目前使用的实体类来自JPA1.0版本,没有共享缓存模式

这样坚持下去

              userTransaction.begin();
              LoggerEntity entity = new LoggerEntity();
              LogEntityPK pk = new LogEntityPK()
              ..
              ..
              ..
              entityManager.persist(entity); 
              userTransaction.commit();



@Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if ( ! (o instanceof LogEntityPK)) {
            return false;
        }
        LogEntityPK other = (LogEntityPK) o;
        return this.calIdNr.equals(other.calIdNr)
            && this.trsTypCd.equals(other.trsTypCd);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int hash = 17;
        hash = hash * prime + this.calIdNr.hashCode();
        hash = hash * prime + this.trsTypCd.hashCode();
        return hash;
    }

LogEntityPK复合主键是如何定义的?'code'@embeddedable public class LogEntityPK实现可序列化的{@Columnname=CAL_ID_NR private String calIdNr;@Columnname=TRS_TYP_CD private String trsTypCd;private static final long serialVersionUID=1L;public LogEntityPK{super;}code@embeddeble public class LogEntityPK实现可序列化{@Columnname=CAL_ID_NR private String calIdNr;@Columnname=TRS_TYP_CD private String trsTypCd;private static final long serialVersionUID=1L;public LogEntityPK{super;}code LogEntityPK实现equals和hashCode方法吗?据我所知,它们是必需的。是的,它们实现了equals和hashcode。更新了主要帖子
              userTransaction.begin();
              LoggerEntity entity = new LoggerEntity();
              LogEntityPK pk = new LogEntityPK()
              ..
              ..
              ..
              entityManager.persist(entity); 
              userTransaction.commit();



@Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if ( ! (o instanceof LogEntityPK)) {
            return false;
        }
        LogEntityPK other = (LogEntityPK) o;
        return this.calIdNr.equals(other.calIdNr)
            && this.trsTypCd.equals(other.trsTypCd);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int hash = 17;
        hash = hash * prime + this.calIdNr.hashCode();
        hash = hash * prime + this.trsTypCd.hashCode();
        return hash;
    }