Java Hibernate 5.4.4中的标准QueryCache替代方案是什么

Java Hibernate 5.4.4中的标准QueryCache替代方案是什么,java,hibernate,caching,Java,Hibernate,Caching,我使用以下代码进行缓存 public class SuiteStandardQueryCache extends StandardQueryCache { public SuiteStandardQueryCache(Settings settings, Properties props, UpdateTimestampsCache updateTimestampsCache, String regionName)

我使用以下代码进行缓存

 public class SuiteStandardQueryCache extends StandardQueryCache {

    public SuiteStandardQueryCache(Settings settings, Properties props, UpdateTimestampsCache updateTimestampsCache, String regionName)
                                                                                                                                       throws HibernateException {
        super(settings, props, updateTimestampsCache, regionName);
    }

    public boolean put(QueryKey key, Type[] returnTypes, List result, boolean isNaturalKeyLookup, SessionImplementor session) throws HibernateException {
        if (isNaturalKeyLookup && result.size() == 0) {
            return false;
        } else {
            Long ts = new Long(session.getTimestamp());
            List cacheable = new ArrayList(result.size() + 1);
            cacheable.add(ts);
            for (int i = 0; i < result.size(); i++) {
                if (returnTypes.length == 1) {
                    // cacheable.add( returnTypes[0].disassemble( result.get( i
                    // ), session, null ) );
                    Object resultObj = result.get(i);
                    if (resultObj instanceof Object[]) {
                        resultObj = ((Object[]) result.get(i))[0];
                    }
                    cacheable.add(returnTypes[0].disassemble(resultObj, session, null));
                } else {
                    cacheable.add(disassemble((Object[]) result.get(i), returnTypes, null, session, null));
                 }
            }
            getRegion().put(key, cacheable);
            return true;
        }
    }


    public static Serializable[] disassemble(final Object[] row,

        return disassembled;
    }
}
公共类SuiteStandardQueryCache扩展了StandardQueryCache{
public SuiteStandardQueryCache(设置、属性道具、UpdateTimestampsCache UpdateTimestampsCache、字符串区域名称)
抛出冬眠异常{
超级(设置、道具、updateTimestampsCache、regionName);
}
公共布尔put(QueryKey键,Type[]returnTypes,List result,boolean isNaturalKeyLookup,SessionImplementor会话)抛出HibernateeException{
if(isNaturalKeyLookup&&result.size()==0){
返回false;
}否则{
Long ts=new Long(session.getTimestamp());
List cacheable=new ArrayList(result.size()+1);
可缓存。添加(ts);
对于(int i=0;i
这段代码是hibernate for hibernate 3,我将把它升级到hibernate 5.4.4,其中没有此类


请帮助找到相同的替代方案。

可以使用您选择的任何二级缓存提供程序配置查询缓存。Hibernate默认没有二级缓存,您必须配置并提供一个()

例如,我使用EhCache作为二级缓存。我通过XML对其进行如下配置:

<cache-template name="default">
    <key-type>java.lang.Object</key-type>
    <value-type>java.lang.Object</value-type>

    <expiry>
      <none/>
    </expiry>

    <heap unit="entries">100000</heap>
</cache-template>

<!-- Configure the caches that Hibernate uses by default. -->
<cache alias="default-query-results-region" uses-template="default" />
<cache alias="default-update-timestamps-region" uses-template="default" />

java.lang.Object
java.lang.Object
100000
我相信由于我的缓存配置,这个缓存使用的Java类最终是
org.ehcache.jsr107.Eh107Cache.Eh107Cache


如果您想按照上面的方法添加自定义逻辑,我相信您要做的是为
hibernate.javax.cache.provider
配置属性设置一个自定义缓存提供程序。我的当前值是
org.ehcache.jsr107.EhcacheCachingProvider
。重写该类以提供一个缓存管理器,该管理器根据您的需要构建缓存

这段代码似乎是为了解决特定的问题或bug而编写的,可能是在Hibernate的早期版本中place@Guillaume这是可能的,但我只是在寻找StandardQueryCache类,这个类的替代方案是什么。谢谢你的回答,我可以做,但我想我不想继续使用以前的代码,只是不想更改我的代码,因为这可能会影响应用程序的其他领域,我正在为StandardQueryCache寻找一些基于代码的替代解决方案,不幸的是,我没有得到任何相同的线索。我要说的是,据我所知,没有替代品——它只使用标准缓存(无论你告诉它什么)。没有专用的查询缓存类。好的,我应该在哪里配置它,这意味着它将是哪个xml文件,我对Hibernate是新手:)另外,请告诉我QueryCacheFactory接口这也是从Hibernate 5.4.4中提取的