Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

Problem with hibernate FetchType.Lazy and Backup spaces

Hi,

I am using initial load to fetch huge amount of data to partitioned space. I have to join a lot of tables and because of performance I am using fetch = FetchType.LAZY when I want to join some more complex objects. I develop some kind of workaround to have all objects in space without LAZY fetching on getters:

  1. Load all very complex object (which have FetchType.LAZY) separately.

    @SpaceClass
    @Entity
    @Table(name = "A")
    public class A  {
    
        @OneToOne(fetch = FetchType.LAZY)
           @JoinColumns({@JoinColumn(name = "b_Id", referencedColumnName ="id"),
           @JoinColumn(name = "b_ValidFrom", referencedColumnName = "validFrom")
        })
        private B b;
    

    in this example I fetch class B and A to space separately.

  2. Creating bean with @PostPrimary method which triggers AggregateObjectsTask which performs joins manually meaning it joins columns inside space :

     B bTemplate = new B();
     bTemplate .setId(a.getId());
     bTemplate .setValidFrom.(a.getB_ValidFrom());
     bObj = gigaSpace.read(bTemplate);
     a.setB(bObj);
     gigaspace.write(a);
    
  3. Primary spaces starts normally but while creating backup space I got these ugly exceptions:

    at com.mypackage.B_$$_javassist_23.equals(B$$_javassist_23.java)
         [4/8000]           at                 com.gigaspaces.internal.cluster.node.impl.packets.data.operations.UpdateReplicationPacketData.serializePreviousFixedValues(UpdateReplicationPacketData.java:400)
     [4/8000]           at com.gigaspaces.internal.cluster.node.impl.packets.data.operations.UpdateReplicationPacketData.serializePreviousEntryData(UpdateReplicationPacketData.java:374)
     [3/15352]          at com.gigaspaces.internal.cluster.node.impl.router.spacefinder.ConnectionReference.dispatch(ConnectionReference.java:53)
     [5/10616]          at java.lang.Thread.run(Thread.java:662)
     [4/8000]           at com.gigaspaces.internal.cluster.node.impl.packets.data.operations.UpdateReplicationPacketData.writeExternalPost91(UpdateReplicationPacketData.java:365)
    
    
     [5/10616]  Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
     [5/10616]          at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:167)
     [3/15352]          at com.gigaspaces.internal.cluster.node.impl.groups.AbstractReplicationSourceChannel$IterativeHandshakeHandler.call(AbstractReplicationSourceChannel.java:1388)
     [5/10616]          at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215)
     [4/8000]           at com.gigaspaces.internal.cluster.node.impl.packets.data.operations.UpdateReplicationPacketData.writeExternal(UpdateReplicationPacketData.java:327)
     [5/10616]          at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
     [3/15352]          at com.gigaspaces.internal.cluster.node.impl.groups.AbstractReplicationSourceChannel$IterativeHandshakeHandler.call(AbstractReplicationSourceChannel.java:1362)
     [5/10616]          at com.mypackage.B_$$_javassist_23.equals(B_$$_javassist_23.java)
     [4/8000]           at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1429)
     [5/10616]          at com.gigaspaces.internal.cluster.node.impl.packets.data.operations.UpdateReplicationPacketData.serializePreviousFixedValues(UpdateReplicationPacketData.java:400)
     [5/10616]          at com.gigaspaces.internal.cluster.node.impl.packets.data.operations.UpdateReplicationPacketData.serializePreviousEntryData(UpdateReplicationPacketData.java:374)
     [3/15352]          at com.gigaspaces.internal.utils.concurrent.ScheduledThreadPoolAsyncHandlerProvider$AsyncRunnableWrapper$ExecutionTask.run(ScheduledThreadPoolAsyncHandlerProvider.java:342)
     [5/10616]          at com.gigaspaces.internal.cluster.node.impl.packets.data.operations.UpdateReplicationPacketData.writeExternalPost91(UpdateReplicationPacketData.java:365)
     [4/8000]           at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1398)
     [5/10616]          at com.gigaspaces.internal.cluster.node.impl.packets.data.operations.UpdateReplicationPacketData.writeExternal(UpdateReplicationPacketData.java:327)
     [3/15352]          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
     [5/10616]          at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1429)
     [5/10616]          at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1398)
     [5/10616]          at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
     [5/10616]          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
     [5/10616]          at com.gigaspaces.internal.cluster.node.impl.backlog.globalorder.GlobalOrderOperationPacket.writeExternal(GlobalOrderOperationPacket.java:113)
     [4/8000]           at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
     [5/10616]          at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1429)
     [3/15352]          at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
     [5/10616]          at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1398)
     [4/8000]           at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
     [5/10616]          at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
     [3/15352]          at java.util.concurrent.FutureTask.run(FutureTask.java:138)
     [5/10616]          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
     [4/8000]           at com.gigaspaces.internal.cluster.node.impl.backlog.globalorder.GlobalOrderOperationPacket.writeExternal(GlobalOrderOperationPacket.java:113)
     [5/10616]          at java.util.LinkedList.writeObject(LinkedList.java:943)
     [3/15352]          at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
     [5/10616]          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [4/8000]           at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1429)
     [5/10616]          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     [3/15352]   [5/10616]          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     [4/8000]           at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1398)
     [4/8000]           at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
     [5/10616]          at java.lang.reflect.Method.invoke(Method.java:597)
            at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
     [5/10616]          at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
     [4/8000]           at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
     [5/10616]          at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1469)
     [3/15352]   [5/10616]          at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
     [4/8000]           at java.util.LinkedList.writeObject(LinkedList.java:943)
     [4/8000]           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [5/10616]          at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
     [5/10616]          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
     [5/10616]          at com.gigaspaces.internal.serialization.ObjectClassSerializer.write(ObjectClassSerializer.java:36)
     [5/10616] [4/8000]             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     [4/8000]           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    at com.gigaspaces.internal.io.IOUtils.writeObject(IOUtils.java:668)
     [3/15352]          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
     [5/10616]          at com.gigaspaces.internal.cluster.node.impl.backlog.reliableasync.ReliableAsyncHandshakeIteration.writeExternal(ReliableAsyncHandshakeIteration.java:44)
     [4/8000]           at java.lang.reflect.Method.invoke(Method.java:597)
     [5/10616]          at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1429)
     [3/15352]          at java.lang.Thread.run(Thread.java:662)
     [5/10616]          at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1398)
     [5/10616]          at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
     [4/8000]           at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
     [5/10616]          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
     [5/10616]          at com.gigaspaces.internal.serialization.ObjectClassSerializer.write(ObjectClassSerializer.java:36)
     [5/10616]          at com.gigaspaces.internal.io.IOUtils.writeObject(IOUtils.java:668)
    

asked 2014-03-27 10:20:14 -0500

Kamil K gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

Hibernate Lazy loading is not supported with initial load - the returned POJOs must be fully populated before they are loaded into the space.

The recommended pattern for speeding up initial load is customizing the query to load only the data relevant to the current partition. For more information refer to the Initial Load documentation.

answered 2014-04-03 10:27:36 -0500

niv gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-03-27 10:20:14 -0500

Seen: 1,540 times

Last updated: Apr 03 '14