Migrating from 4.2.21.Final to 5.3.4.Final. Ehcache 2.10.3. CacheKey is removed since 5.0 it seems. Its mentioned in the 5.0 Javadoc but its not in the jar so I guess its gone. Not mentioned in 5.3.4 docs.
Didn’t see a @deprecated notice in the Javadocs 4.3.11.Final. Can’t find any info about in the 5.x migration guides. Have googled a lot and read the Hibernate forums. Very little info except for CacheKey class missing from Hibernate 5 API. But the code mentioned does not exist in DefaultLoadEventListener for 5.3.4. Perhaps because of the 5.3.4 chapter’Second-level cache provider SPI changes’
Could you please tell me what has come in place of CacheKey? Any hints/pointers would be very much appreciated.
final EntityDataAccess cache = persister.getCacheAccessStrategy();
final Object ck = cache.generateCacheKey(
event.getEntityId(),
persister,
source.getFactory(),
source.getTenantIdentifier()
);
We have a CompanyCacheImpl class which extends CacheImpl. The four @Overrides for CacheImpl like evictEntity use Cachekey.
Example:
@Override
public void evictEntity(String entityName, Serializable identifier) {
EntityPersister p = m_sessionFactory.getEntityPersister(entityName);
if (p.hasCache()) {
LOG.debug("Evicting second-level cache for EntityPersister {} and Identifier {} with SessionFactory {}", p, identifier, m_sessionFactory);
p.getCacheAccessStrategy().evict(buildCacheKey(identifier, p));
}
}
// our code
private CacheKey buildCacheKey(Serializable identifier, EntityPersister p) {
return new CacheKey(identifier,
p.getIdentifierType(),
p.getRootEntityName(),
TenantContextHolder.getContext().getTenantLabel(),
m_sessionFactory);
}
It turns out CacheImpl has disappeared in 5.3.x so the code is not relevant anylonger. As in CompanyCacheServiceInitiator (implements Hibernates) SessionFactoryServiceInitiator returns a new CompanyCacheImpl object does no longer work. For now to get rid of compile errors I’m returning a new DisabledCaching(…) object which implements a CacheImplementor object.
Later on I think I’ve to switch to EnabledCaching(…). Figuring out how to evict our data will be a fight for another day. So far haven’t dealt with Hibernate on this low level, normally creating new domain objects etc…
Thanks for the fast reply, very much appreciated. I’ve this feeling in the next days I’ve to revisit this forum again if/when I’m stuck…
Any suggestion for a blog, website, book for info about Hibernate 5.3.x??
As in CompanyCacheServiceInitiator (implements Hibernates) SessionFactoryServiceInitiator returns a new CompanyCacheImpl object does no longer work.
SessionFactoryServiceInitiator is for initiating Hibernate Service instances, and it does not return any CompanyCacheImpl.
Extending internal Hibernate code requires a lot of rewriting on the long-run. That’s why is better to use the SPI classes whenever you need to customize Hibernate.
Any suggestion for a blog, website, book for info about Hibernate 5.3.x??
I doubt there’s anything like that. Just use the HIbernate 5.3 source code to see how it has changed from 4.2 and adapt your code accordingly.