You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by kestas <ka...@gmail.com> on 2018/06/25 10:37:51 UTC
ClassCastException in Hibernate QueryCache
Using Ignite 2.4 for Hibernate query cache and getting an exception:
Caused by: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast
to [Ljava.io.Serializable;
at
org.hibernate.cache.internal.StandardQueryCache.get(StandardQueryCache.java:189)
at org.hibernate.loader.Loader.getResultFromQueryCache(Loader.java:2587)
The problematic line in Hibernate reads:
TypeHelper.beforeAssemble( (Serializable[]) cacheable.get( i ), returnTypes,
session );
it receives Object[] from the cache and tries to cast to Serializable[]
which obviously fails. It seems to be a generic place and should not work
for anyone, but somehow it is working?
I did check put operation and it actually puts Serializable[] into the
cache.
Any pointers on how to resolve the issue?
Cache config used is very simple taken from examples.
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: ClassCastException in Hibernate QueryCache
Posted by aealexsandrov <ae...@gmail.com>.
Hi,
I think that the problem is that next code doesn't work in java:
public static class SerializableObject implements Serializable {}
and
Object[] array = new Object[1];
array[0] = new SerializableObject();
Serializable[] serializableArr = (Serializable[]) array;
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object;
cannot be cast to [Ljava.io.Serializable;
But next code works ok:
SerializableObject[] array = new SerializableObject[1];
array[0] = new SerializableObject();
Serializable[] serializableArr = (Serializable[]) array;
BR,
Andrei
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: ClassCastException in Hibernate QueryCache
Posted by Kestas <ka...@gmail.com>.
Attaching ignite config. A failed code is a simple execution of hibernate
query. Here is bigger stacktrace:
Caused by: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast
to [Ljava.io.Serializable;
at
org.hibernate.cache.internal.StandardQueryCache.get(StandardQueryCache.java:189)
at org.hibernate.loader.Loader.getResultFromQueryCache(Loader.java:2587)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2495)
at org.hibernate.loader.Loader.list(Loader.java:2467)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502)
at
org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:384)
at
org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1490)
at
org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445)
at
org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414)
at org.hibernate.query.Query.getResultList(Query.java:146)
at
com.aaa.bbb.base.dataload.dao.GenericJpaQueryDAO.executeGenericQuery(GenericJpaQueryDAO.java:55)
For now I created 'dirty' workaround to continue with my testing:
org.apache.ignite.cache.hibernate.HibernateQueryResultsRegion#get
@Override
public Object get(SharedSessionContractImplementor
sharedSessionContractImplementor, Object key) throws CacheException {
Object result = super.get(sharedSessionContractImplementor, key);
if (result instanceof List) {
List list = (List) result;
if (list.size() > 1) {
for (int i = 1; i < list.size(); i++) {//first element in
list is id, skip it
Object row = list.get(i);
if (row != null && row.getClass().isArray())
{//convert Object[] to Serializable[]
Object[] rowArr = (Object[]) row;
list.set(i, Arrays.copyOf(rowArr, rowArr.length,
Serializable[].class));
}
}
}
}
return result;
}
On Mon, Jun 25, 2018 at 9:41 PM aealexsandrov <ae...@gmail.com>
wrote:
> Hi,
>
> Could you please provide some more details: cache configuration, an example
> of code that was failed and logs?
>
> BR,
> Andrei
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
Re: ClassCastException in Hibernate QueryCache
Posted by aealexsandrov <ae...@gmail.com>.
Hi,
Could you please provide some more details: cache configuration, an example
of code that was failed and logs?
BR,
Andrei
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/