Cannot make a LazyForeignCollection become eager c

2019-05-28 01:33发布

问题:

I'm getting this error when trying to read a foreign collection from my POJO

AndroidRuntime(589): Caused by: java.lang.IllegalStateException: Internal DAO
    object is null.  Lazy collections cannot be used if they have been deserialized.

The offending collection is answers1 which i have marked as 'eager'

@ForeignCollectionField (eager=true)
private ForeignCollection<TextAnswer> answers1;

Why then when I debug the method below

public List<TextAnswer> getAnswers() {      
    return new ArrayList<TextAnswer>(answers1);
}

That it tells me the collection is a LazyForeignCollection? I am puzzled.

I have no prob with this in any of my other classes that use ForeignCollections :(

回答1:

Lazy collections cannot be used if they have been deserialized.

Interesting problem. First off, that message is only in the LazyForeignCollection class. Is there any chance that the answer1 field used to be lazy and was serialized? Is serialization involved at all? The dao field inside of a ForeignCollection should never be null unless the object has been serialized.

My assumption right now is that you are deserializing a previous version of the class. If this is not the case then I have no idea.