Problem in document fetching in couchbase lite(offline) by code


#1

hi,
I am trying to fetch the document using view and query.
I am running query.run and getting QueryEnumerator,
and tryin to fetch values by QueryEnumerator ref .getdocument() function,
It giving document which i have store,
Now,
At the time of storing document i have stored documet as (key , my POJO class object),
at at the time of retrieval it giving me JAVA object , i have tried to do typecasting but it is giving error as follows:

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.kpit.ecueditor.newdtc.entity.Dtc

eventhough it should store the object in Dtc object but it is not allowing me, and i am not able to retrieve data from objecy,

Any idea what should i do?


#2

Hi @shriram.punde,

Not sure I fully understand the issue you’re encountering. You should store the document as a set of JSON key, value pairs and when retrieving them you can deserialize the JSON as a POJO class.

Check out this blog post on using Jackson’s databind feature to automatically map the JSON to properties and vice versa. http://blog.couchbase.com/2016/july/object-mapping-couchbase-mobile-android

James


#3

@jamiltz
i have another one doubt , i am deleting document from couchbase lite (offline local db) , but by sync gateway it is connected to the server , and push -pull operations are going on,
my doubt is after deleting that document is it pulled again from server or it’ll also get deleted from server?


#4

Deleting a document creates a tombstone that’s replicated to other databases like the server. It won’t pull the document in future replications. See docs on deleting http://developer.couchbase.com/documentation/mobile/1.3/guides/couchbase-lite/native-api/document/index.html#deleting-documents

However, if you purge the document it will pull the document from the server again in a replication that starts from the beginning. See docs on purging http://developer.couchbase.com/documentation/mobile/1.3/guides/couchbase-lite/native-api/document/index.html#purging-documents

James


#5

got it… thank u so much :slight_smile: