Riak Java client questions

Brian Roach roach at basho.com
Thu Aug 2 13:46:51 EDT 2012


Hi Oved - replies inlined below.


On Aug 2, 2012, at 11:04 AM, Oved Machlev wrote:

> Hi,
>  
> I have been working with Riak in past 3 weeks, using the java client.
> I have encountered a few issues, and could not find solutions so far.
> This is the first time I write an email to this mailing list - Would be great if it reaches the right destination J
>  
> 1.       Riak supports auto generated keys when storing an object - http://wiki.basho.com/Basic-Riak-API-Operations.html:
> Store a new object and assign random key #
> 
> If your application would rather leave key-generation up to Riak, issue a POST request to the bucket URL instead of a PUT to a bucket/key pair: POST /riak/bucket If you don’t pass Riak a “key” name after the bucket, it will know to create one for you.
> 
> Is it possible to do the same when using the java client? it seems that key must be provided when storing an object.
> 

Right now the Java client doesn't support this. These is an issue open for this on github and I agree it needs to be added. 

After the 1.0.6 release (along with Riak 1.2) I hope to work on this and get it added. 

> 2.       I have a POJO which I store. It contains a set of objects which I do not wish to persist, I mark it as transient:
>  
> transient private Set<Service> services;
> but still, this set is being persisted – when I fetch my POJO (curl and java) I can see this:
>  
>                 {"name":"oved","lastUpdate":"1343923201735","data":null,"services":[]}
>  
> Is there something else I need to do to tell Riak to ignore it?
>  

The default Converter<T> used if you do not specify your own is the JSONConverter. This uses the Jackson JSON library. 

To exclude a field from serialization you would need to use the (org.codehaus.jackson.annotate) @JsonIgnore annotation. 

> 3.       This is more basic question – I keep on thinking that my stored objects should implement the IRIAKObject, but I avoided doing that so far, because in all the examples in the cookbook, it is never being done. So in theoretical level – should the objects that are stored in riak database implement this interface or not? Is there any value in doing that?
>  

Not particularly. That's what the Converter<T> is doing behind the scenes; converting back and forth between your POJO and a IRiakObject


> 4.       MapReduce – If I perform the following without the line in bold (link) I get the collection of ServiceProviders without the Services that are linked.
> When adding the LinkPhase, I am getting a JsonMappingException (see below). Any idea what is causing that? What am I missing? Both objects (service and serviceProvider) are stored as JsonObjects.
>  
>     public Collection<ServiceProvider> getAllServiceProvider() throws Exception{
> 
>         BucketMapReduce m = riakClient.mapReduce("SERVICE_PROVIDER");
>         m.addMapPhase(new NamedJSFunction("Riak.mapValuesJson"), true);
>         m.addLinkPhase("SERVICE", "_");
>         MapReduceResult result = m.execute();       
>         return result.getResult(ServiceProvider.class);
>     }
> 
>  
> The exception:
> com.basho.riak.client.convert.ConversionException: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of com.att.cso.omss.datastore.riak.entities.ServiceProvider out of START_ARRAY token
>  at [Source: java.io.StringReader at 31958905; line: 1, column: 2]
>     at com.basho.riak.client.raw.http.ConversionUtil$1.getResult(ConversionUtil.java:601)
> 
>  

Jackson is having some issue trying to map the JSON returned to your ServiceProvider class. Can you check the JSON stored in Riak and make sure it's what you think it is? If I could see the class and the JSON I might be able to offer more insight.


> Sorry for the long email, and thanks in advance…

No Worries!

Thanks,
Brian Roach





More information about the riak-users mailing list