Reputation: 33
When I add or remove a column from an entity and the "old" entity was already in the cache and I want to load the "new" entity now I get an error. I use Redisson as 2LD Cache in Hibernate.
"Old" Entity:
public class TestEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "p_id", updatable = false, unique = true, nullable = false)
private Long id;
@NaturalId
@Column(name = "p_uuid")
private String uuid;
@Column(name = "p_name")
private String name;
@Column(name = "test_int")
private int test;
}
"New" Entity:
public class TestEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "p_id", updatable = false, unique = true, nullable = false)
private Long id;
@NaturalId
@Column(name = "p_uuid")
private String uuid;
@Column(name = "p_name")
private String name;
@Column(name = "test_int")
private int test;
@Column(name = "bool")
private boolean bool; //new column
}
Error:
java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3 at org.hibernate.type.TypeHelper.assemble(TypeHelper.java:97) at org.hibernate.cache.spi.entry.StandardCacheEntryImpl.assemble(StandardCacheEntryImpl.java:135) at org.hibernate.loader.entity.CacheEntityLoaderHelper.convertCacheEntryToEntity(CacheEntityLoaderHelper.java:308) at org.hibernate.loader.entity.CacheEntityLoaderHelper.processCachedEntry(CacheEntityLoaderHelper.java:174) at org.hibernate.loader.entity.CacheEntityLoaderHelper.loadFromSecondLevelCache(CacheEntityLoaderHelper.java:147) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:523) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:208) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:327) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:108) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:74) at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:118) at org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1215) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1204) at org.hibernate.internal.SessionImpl.access$2100(SessionImpl.java:203) at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.doLoad(SessionImpl.java:2819) at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.lambda$load$1(SessionImpl.java:2796) at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.perform(SessionImpl.java:2752) at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2796) at org.hibernate.internal.SessionImpl$SimpleNaturalIdLoadAccessImpl.load(SessionImpl.java:3241) at
I also don't want to clear the entity from the cache as it won't do anything since I have several applications running at the same time and it can always happen that they don't have the latest entities and to guarantee high availability I can't always restart them. Without redisson cache it works of course, but I want to use a second level cache for performance reasons. Does anyone have a suggestion on how best to handle this?
Hibernate-Version: 5.5.2.Final
Upvotes: 3
Views: 645
Reputation: 16452
Seems like this question was recently asked: https://discourse.hibernate.org/t/hibernate-second-level-cache-no-fallback-to-db-if-deserialization-fails/5516
There is no way to handle this currently.
Upvotes: 2