org.hibernate.LazyInitializationException when de-serializing

1,332 views
Skip to first unread message

Troy Collinsworth

unread,
May 21, 2013, 4:22:33 PM5/21/13
to kryo-...@googlegroups.com
Is there a special serializer that needs to be registered for hibernate to avoid LazyInitializationException? I found this HibernateCollectionsSerializerFactory, but it doesn't appear to be compatible.

The hibernate mappings are all set to default-lazy="false" and I've set the offending property to lazy="false" and even tried fetch="join", but it still fails with the LazyInitializationException.

org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:365)
at org.hibernate.collection.PersistentSet.add(PersistentSet.java:212)
at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:109)

Kryo 2.21
Kryo serializers 0.22
Hibernate 3.3.2.GA

Kyro setup:

    kryoSerializer.setInstantiatorStrategy(new SerializingInstantiatorStrategy());

    kryoSerializer.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
    UnmodifiableCollectionsSerializer.registerSerializers(kryoSerializer);
    SynchronizedCollectionsSerializer.registerSerializers(kryoSerializer);

Martin Grotzke

unread,
May 22, 2013, 5:06:05 AM5/22/13
to kryo-...@googlegroups.com
Please try this:

kryoSerializer = new Kryo() {
@Override
public Serializer<?> getDefaultSerializer( final Class type ) {
if (AbstractPersistentCollection.class.isAssignableFrom( type )) {
return new FieldSerializer( kryoSerializer, type );
}
return super.getDefaultSerializer( type );
}
}

AbstractPersistentCollection is
org.hibernate.collection.AbstractPersistentCollection.

Cheers,
Martin
> --
> You received this message because you are subscribed to the "kryo-users"
> group.
> http://groups.google.com/group/kryo-users
> ---
> You received this message because you are subscribed to the Google
> Groups "kryo-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to kryo-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
inoio gmbh - http://inoio.de
Schulterblatt 36, 20357 Hamburg
Amtsgericht Hamburg, HRB 123031
Geschäftsführer: Dennis Brakhane, Martin Grotzke, Ole Langbehn

signature.asc

Troy Collinsworth

unread,
May 22, 2013, 9:08:14 AM5/22/13
to kryo-...@googlegroups.com, martin....@googlemail.com
Excellent, thanks for the quick response! Initial tests, indicate this resolved the issue.

Troy
Reply all
Reply to author
Forward
0 new messages