debop / hibernate-redis

hibernate 2nd level cache privder using redis
Apache License 2.0
358 stars 182 forks source link

Enum serilization issue #19

Closed apotapov closed 10 years ago

apotapov commented 10 years ago

I have the following enum that serves as a field on a hibernate entity:

package com.bvg.models.enums;

public enum Gender {
    MALE,
    FEMALE
}

Entity:

@Entity
@Table(name = "users")
@Getter
@Setter
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class User extends AbstractModel implements Subject {
...
@Enumerated(EnumType.STRING)
    @Column
    protected Gender gender;
...
}

I have configured hibernate-redis as per instructions, and things seem to work fine for entities that use primitive types for fields (String, int, boolean, etc) However, this enum is giving me trouble. Do I need to register it with the serializer somehow? Seems like it should be able to handle an enum.

Here's the stack trace that i get:

22:48:59.295 [application-akka.actor.default-dispatcher-9] WARN  o.h.c.r.s.FstRedisSerializer.deserialize 53 - Fail to deserialize bytes.
java.io.IOException: java.lang.RuntimeException: CLASSNAME:com.bvg.models.enums.Gender
    at de.ruedigermoeller.serialization.FSTObjectInput.readObject(FSTObjectInput.java:168) ~[fst-1.53.jar:na]
    at org.hibernate.cache.redis.serializer.FstRedisSerializer.deserialize(FstRedisSerializer.java:51) ~[hibernate-redis-1.5.10.jar:na]
    at org.hibernate.cache.redis.serializer.SnappyRedisSerializer.deserialize(SnappyRedisSerializer.java:41) [hibernate-redis-1.5.10.jar:na]
    at org.hibernate.cache.redis.jedis.JedisClient.deserializeValue(JedisClient.java:475) [hibernate-redis-1.5.10.jar:na]
    at org.hibernate.cache.redis.jedis.JedisClient.get(JedisClient.java:165) [hibernate-redis-1.5.10.jar:na]
    at org.hibernate.cache.redis.regions.RedisTransactionalDataRegion.get(RedisTransactionalDataRegion.java:75) [hibernate-redis-1.5.10.jar:na]
    at org.hibernate.cache.redis.strategy.AbstractReadWriteRedisAccessStrategy.get(AbstractReadWriteRedisAccessStrategy.java:52) [hibernate-redis-1.5.10.jar:na]
    at org.hibernate.engine.internal.CacheHelper.fromSharedCache(CacheHelper.java:55) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
    at org.hibernate.engine.internal.CacheHelper.fromSharedCache(CacheHelper.java:67) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
    at org.hibernate.event.internal.DefaultLoadEventListener.loadFromSecondLevelCache(DefaultLoadEventListener.java:597) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
    at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:451) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
    at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:212) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
    at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:274) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
    at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
    at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1070) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
    at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:176) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
    at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2551) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
    at org.hibernate.internal.SessionImpl.get(SessionImpl.java:955) [hibernate-core-4.3.4.Final.jar:4.3.4.Final]
    at com.bvg.models.daos.DaoImpl.get(DaoImpl.java:78) [classes/:na]
    at com.bvg.models.daos.DaoImpl.getWithRetry(DaoImpl.java:83) [classes/:na]
    at com.bvg.actors.DbBasedActor.execute(DbBasedActor.java:52) [classes/:na]
    at com.bvg.actors.DbBasedActor.execute(DbBasedActor.java:16) [classes/:na]
    at com.bvg.models.session.HibernateSessionHelper.executeTransactionally(HibernateSessionHelper.java:82) [classes/:na]
    at com.bvg.actors.DbBasedActor.onReceive(DbBasedActor.java:37) [classes/:na]
    at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:167) [akka-actor_2.10.jar:2.2.0]
    at akka.actor.ActorCell.receiveMessage(ActorCell.scala:498) [akka-actor_2.10.jar:2.2.0]
    at akka.actor.ActorCell.invoke(ActorCell.scala:456) [akka-actor_2.10.jar:2.2.0]
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:237) [akka-actor_2.10.jar:2.2.0]
    at akka.dispatch.Mailbox.run(Mailbox.scala:219) [akka-actor_2.10.jar:2.2.0]
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386) [akka-actor_2.10.jar:2.2.0]
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library.jar:na]
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library.jar:na]
Caused by: java.lang.RuntimeException: CLASSNAME:com.bvg.models.enums.Gender
    at de.ruedigermoeller.serialization.FSTClazzNameRegistry.classForName(FSTClazzNameRegistry.java:198) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTClazzNameRegistry.classForName(FSTClazzNameRegistry.java:178) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTClazzNameRegistry.decodeClass(FSTClazzNameRegistry.java:161) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.readClass(FSTObjectInput.java:879) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.instantiateEnum(FSTObjectInput.java:335) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.instantiateSpecialTag(FSTObjectInput.java:272) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.readObjectWithHeader(FSTObjectInput.java:254) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.readArray(FSTObjectInput.java:816) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.instantiateArray(FSTObjectInput.java:325) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.instantiateSpecialTag(FSTObjectInput.java:287) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.readObjectWithHeader(FSTObjectInput.java:254) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.readObjectFields(FSTObjectInput.java:522) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.instantiateAndReadNoSer(FSTObjectInput.java:402) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.readObjectWithHeader(FSTObjectInput.java:261) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.readObjectInternal(FSTObjectInput.java:230) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.readObject(FSTObjectInput.java:210) ~[fst-1.53.jar:na]
    at de.ruedigermoeller.serialization.FSTObjectInput.readObject(FSTObjectInput.java:165) ~[fst-1.53.jar:na]
    ... 33 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.bvg.models.enums.Gender
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372) ~[na:1.8.0_05]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.8.0_05]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_05]
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[na:1.8.0_05]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_05]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_05]
    at java.lang.Class.forName0(Native Method) ~[na:1.8.0_05]
    at java.lang.Class.forName(Class.java:340) ~[na:1.8.0_05]
    at de.ruedigermoeller.serialization.FSTClazzNameRegistry.classForName(FSTClazzNameRegistry.java:184) ~[fst-1.53.jar:na]
    ... 49 common frames omitted
debop commented 10 years ago

Well... try test enumerated entity example

debop commented 10 years ago

Oh! hibernate-redis use Fast-Serialization FST not support jdk 8, I guess try to use JDK 6 or JDK 7

apotapov commented 10 years ago

But lambda functions are so sexy!

I'll file a bug for FST to support java 8.

RuedigerMoeller commented 10 years ago

I'd speculate its a classpath/classloader issue. This does not look like a FST error as you can see it is looking for a perfectly valid classname, but cannot load it. NOte that with 1.55 there is a setClassLoader on the FSTConfiguration in case you have to deal with custom classloaders, however this seems more like a setup problem.

apotapov commented 10 years ago

Thanks for looking into it. I would prefer not to roll my own classloader for this purpose.

I filed a bug with FST. I will try to get a reproducible test for FST and hopefully we can figure out the issue. I'll keep you posted.

apotapov commented 10 years ago

This has nothing to do with Java 8 after all. Looks like this is an issue with Playframework and their classloaders:

playframework/playframework#2847

Apologies for the confusion.