Objectify - UnsupportedOperationException when loading entity by id in transaction

StackOverflow https://stackoverflow.com/questions/22695166

  •  22-06-2023
  •  | 
  •  

Вопрос

I have a User class which inherits from a Page class. In a transaction I wish to load a User entity by ID (obtained from a different entity), but I get a LoadException caused by an UnsupportedOperationException. I'm using objectify 4.0-rc2.

User user = MyObjectifyService.ofy().load().type(User.class).id(info.user).now();

The exception is:

com.googlecode.objectify.LoadException: Error loading Page(5629499534213120): null
at com.googlecode.objectify.impl.Transmog.load(Transmog.java:76)
at com.googlecode.objectify.impl.ConcreteEntityMetadata.load(ConcreteEntityMetadata.java:121)
at com.googlecode.objectify.impl.PolymorphicEntityMetadata.load(PolymorphicEntityMetadata.java:164)
at com.googlecode.objectify.impl.LoadEngine.load(LoadEngine.java:220)
at com.googlecode.objectify.impl.LoadEngine$1.nowUncached(LoadEngine.java:178)
at com.googlecode.objectify.impl.LoadEngine$1.nowUncached(LoadEngine.java:164)
at com.googlecode.objectify.util.ResultCache.now(ResultCache.java:30)
at com.googlecode.objectify.impl.Round$1.nowUncached(Round.java:73)
at com.googlecode.objectify.util.ResultCache.now(ResultCache.java:30)
at com.googlecode.objectify.LoadResult.now(LoadResult.java:25)
...
com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:487)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.UnsupportedOperationException
    at java.util.AbstractList.remove(Unknown Source)
    at java.util.AbstractList$Itr.remove(Unknown Source)
    at java.util.AbstractList.removeRange(Unknown Source)
    at java.util.AbstractList.clear(Unknown Source)
    at com.googlecode.objectify.impl.translate.CollectionTranslatorFactory$1.loadListIntoExistingCollection(CollectionTranslatorFactory.java:66)
    at com.googlecode.objectify.impl.TranslatableProperty.executeLoad(TranslatableProperty.java:62)
    at com.googlecode.objectify.impl.translate.ClassTranslator.loadMap(ClassTranslator.java:115)
    at com.googlecode.objectify.impl.translate.MapNodeTranslator.loadAbstract(MapNodeTranslator.java:25)
    at com.googlecode.objectify.impl.translate.AbstractTranslator.load(AbstractTranslator.java:25)
    at com.googlecode.objectify.impl.Transmog.load(Transmog.java:82)
    at com.googlecode.objectify.impl.Transmog.load(Transmog.java:71)
    ... 68 more
Это было полезно?

Решение

You are loading data into a collection field. Objectify uses an existing collection if the field is already initialized with one (thus you can have collections with special sort Comparators, etc). It looks like you have initialized your collection field with some sort of unmodifiable list.

Initialize the list with a normal ArrayList or whatever you want.

Другие советы

Maybe it's related but I don't think, there's an Immutable collection here too, but the error happens when GAE is turned off and statred the first time (more details here: https://code.google.com/p/objectify-appengine/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=165)

java.lang.NullPointerException
    at com.googlecode.objectify.impl.Round$1.nowUncached(Round.java:73)
    at com.googlecode.objectify.util.ResultCache.now(ResultCache.java:30)
    at com.googlecode.objectify.util.ResultNowFunction.apply(ResultNowFunction.java:20)
    at com.googlecode.objectify.util.ResultNowFunction.apply(ResultNowFunction.java:9)
    at com.google.common.collect.Iterators$8.transform(Iterators.java:860)
    at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
    at com.googlecode.objectify.impl.Chunk.next(Chunk.java:27)
    at com.googlecode.objectify.impl.Chunk.next(Chunk.java:10)
    at com.google.common.collect.Iterators$5.next(Iterators.java:607)
    at com.google.common.collect.Iterators$PeekingImpl.peek(Iterators.java:1239)
    at com.googlecode.objectify.impl.ChunkingIterator.hasNext(ChunkingIterator.java:52)
    at com.google.common.collect.Lists.newArrayList(Lists.java:144)
    at com.google.common.collect.Lists.newArrayList(Lists.java:125)
    at com.googlecode.objectify.util.MakeListResult.translate(MakeListResult.java:21)
    at com.googlecode.objectify.util.MakeListResult.translate(MakeListResult.java:11)
    at com.googlecode.objectify.util.ResultTranslator.nowUncached(ResultTranslator.java:21)
    at com.googlecode.objectify.util.ResultCache.now(ResultCache.java:30)
    at com.googlecode.objectify.util.ResultProxy.invoke(ResultProxy.java:34)
    at com.sun.proxy.$Proxy21.iterator(Unknown Source)
    at java.util.Collections$UnmodifiableCollection$1.<init>(Collections.java:1064)
    at java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1063)
    at flexjson.transformer.IterableTransformer.transform(IterableTransformer.java:26)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top