loading space objects from database

His.

I noticed that in my code when the ManyToOne relationship between objects (many Stocks are traded at a single StockExchange) everything works ok: Persistant objects are written to the database with proper relationships and read into space on space start successfully.

@Entity @SpaceClass(persist = true) public class Stock implements Serializable { . . . . . . @ManyToOne private StockExchange exchange; }

@Entity @SpaceClass(persist = true) public class StockExchange implements Serializable { . . . . . . @Id private String id; private String symbol; }

Should I however make the OneToMany relationship bidirectional

@Entity @SpaceClass(persist = true) public class StockExchange implements Serializable { . . . . . . @Id private String id; private String symbol;

    @OneToMany(mappedBy = "exchange")
private Set<Stock> stocks = new HashSet<Stock>();

}

the errors appear after the space starts anew and reads databased records, and the feeder tries start Stock updates:

@SpaceDataEvent
public Stock dataProcessed(StockFeedEntry data, GigaSpace space) {
    Stock stockView = readStockView(data.getSymbol(), space);
    StockExchange stockExchangeView = readStockExchangeView(data
            .getExchange(), space);
    if (null == stockView) {
        stocksConvertedCount.getAndIncrement();
        stockView = new Stock(UuidFactory.generate().toString(), data
                .getSymbol(), data.getCompanyName(), stockExchangeView,
                data.getCurrentPrice());
    } else {
        stocksUpdatedCount.getAndIncrement();
        stockView.setCurrentPrice(data.getCurrentPrice());
    }
    log.info(stockView);
    return stockView;
}

While I am also not able to query StockExchange objects from the Management Center (and can the Stock objects), the error in the console reads:

SCHWERWIEGEND [org.openspaces.events.polling.SimplePollingEventListenerContainer]: [stockConverterContainer] Execution of event listener failed org.openspaces.events.adapter.ListenerExecutionFailedException: Listener event method 'dataProcessed' threw exception; nested exception is org.openspaces.core.UncategorizedSpaceException: failed to lazily initialize a collection of role: org.openspaces.example.stock.common.StockExchange.stocks, no session or session was closed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.openspaces.example.stock.common.StockExchange.stocks, no session or session was closed at org.openspaces.events.adapter.AbstractReflectionEventListenerAdapter.onEventWithResult(AbstractReflectionEventListenerAdapter.java:153) at org.openspaces.events.adapter.AbstractResultEventListenerAdapter.onEvent(AbstractResultEventListenerAdapter.java:79) at org.openspaces.events.AbstractEventListenerContainer.invokeListener(AbstractEventListenerContainer.java:136) at org.openspaces.events.polling.AbstractPollingEventListenerContainer.doReceiveAndExecute(AbstractPollingEventListenerContainer.java:371) at org.openspaces.events.polling.AbstractPollingEventListenerContainer.receiveAndExecute(AbstractPollingEventListenerContainer.java:332) at org.openspaces.events.polling.SimplePollingEventListenerContainer$AsyncEventListenerInvoker.invokeListener(SimplePollingEventListenerContainer.java:676) at org.openspaces.events.polling.SimplePollingEventListenerContainer$AsyncEventListenerInvoker.run(SimplePollingEventListenerContainer.java:617) at java.lang.Thread.run(Thread.java:619) Caused by: org.openspaces.core.UncategorizedSpaceException: failed to lazily initialize a collection of role: org.openspaces.example.stock.common.StockExchange.stocks, no session or session was closed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.openspaces.example.stock.common.StockExchange.stocks, no session or session was closed at org.openspaces.core.exception.DefaultExceptionTranslator.translate(DefaultExceptionTranslator.java:51) at org.openspaces.core.DefaultGigaSpace.read(DefaultGigaSpace.java:183) at org.openspaces.core.DefaultGigaSpace.read(DefaultGigaSpace.java:175) at org.openspaces.core.DefaultGigaSpace.read(DefaultGigaSpace.java:171) at org.openspaces.example.stock.processor.StockFeedConverter.readStockExchangeView(StockFeedConverter.java:96) at org.openspaces.example.stock.processor.StockFeedConverter.dataProcessed(StockFeedConverter.java:61) at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.openspaces.events.adapter.AbstractReflectionEventListenerAdapter.onEventWithResult(AbstractReflectionEventListenerAdapter.java:148) ... 7 more Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.openspaces.example.stock.common.StockExchange.stocks, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86) at org.hibernate.collection.PersistentSet.hashCode(PersistentSet.java:411) at com.j_spaces.core.EntryHolder.quickReject(SourceFile:300) at com.j_spaces.obf.pw.a(SourceFile:3181) at com.j_spaces.obf.pw.a(SourceFile:3762) at com.j_spaces.obf.kx.a(SourceFile:676) at com.j_spaces.obf.pw.b(SourceFile:1283) at com.j_spaces.obf.pw.a(SourceFile:1166) at com.j_spaces.core.JSpaceImpl.read(SourceFile:469) at com.j_spaces.core.lrmi.LRMIRemoteSpaceImpl.read(SourceFile:220) at com.j_spaces.core.cluster.JSpaceClusteredProxy.internalRead(SourceFile:1994) at com.j_spaces.core.cluster.JSpaceClusteredProxy.readBasic(SourceFile:1869) at com.j_spaces.core.cluster.action.ClusterSpaceReadActionListener.onAction(SourceFile:59) at com.j_spaces.core.cluster.action.ClusterSpaceReadActionListener.onAction(SourceFile:19) at com.j_spaces.core.client.AbstractSpaceProxy.read(SourceFile:171) at com.j_spaces.core.client.AbstractSpaceProxy.read(SourceFile:160) at org.openspaces.core.DefaultGigaSpace.read(DefaultGigaSpace.java:181) ... 15 more

09.09.2008 13:03:26 SCHWERWIEGEND [org.hibernate.LazyInitializationException]: failed to lazily initialize a collection of role: org.openspaces.example.stock.common.StockExchange.stocks, no session or session was closed org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.openspaces.example.stock.common.StockExchange.stocks, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86) at org.hibernate.collection.PersistentSet.hashCode(PersistentSet.java:411) at com.j_spaces.core.EntryHolder.quickReject(SourceFile:300) at com.j_spaces.obf.pw.a(SourceFile:3181) at com.j_spaces.obf.pw.a(SourceFile:3762) at com.j_spaces.obf.kx.a(SourceFile:676) at com.j_spaces.obf.pw.b(SourceFile:1283) at com.j_spaces.obf.pw.a(SourceFile:1166)

    at com.j_spaces.core.JSpaceImpl.read(SourceFile:469)
    at com.j_spaces.core.lrmi.LRMIRemoteSpaceImpl.read(SourceFile:220)
    at com.j_spaces.core.cluster.JSpaceClusteredProxy.internalRead(SourceFile:1994)
    at com.j_spaces.core.cluster.JSpaceClusteredProxy.readBasic(SourceFile:1869)
    at com.j_spaces.core.cluster.action.ClusterSpaceReadActionListener.onAction(SourceFile:59)
    at com.j_spaces.core.cluster.action.ClusterSpaceReadActionListener.onAction(SourceFile:19)
    at com.j_spaces.core.client.AbstractSpaceProxy.read(SourceFile:171)
    at com.j_spaces.core.client.AbstractSpaceProxy.read(SourceFile:160)
    at org.openspaces.core.DefaultGigaSpace.read(DefaultGigaSpace.java:181)
    at org.openspaces.core.DefaultGigaSpace.read(DefaultGigaSpace.java:175)
    at org.openspaces.core.DefaultGigaSpace.read(DefaultGigaSpace.java:171)
    at org.openspaces.example.stock.processor.StockFeedConverter.readStockExchangeView(StockFeedConverter.java:96)
    at org.openspaces.example.stock.processor.StockFeedConverter.dataProcessed(StockFeedConverter.java:61)
    at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method ...
(more)

asked 2008-09-09 06:24:28 -0600

asdfasdf gravatar image

updated 2013-08-08 09:52:00 -0600

jaissefsfex gravatar image
edit retag flag offensive close merge delete