0

I want to store a Riak Pojo object with links in the database using the java. Eventhough the field type is Collection <RiakLink>, it keep throwing the same exception "riak links field must be Collection <RiakLink> ".

Code: class Pojo{

public String name;

@RiakKey
public String key;

@RiakLinks
@JsonIgnore  
public Collection<RiakLink> collection = new ArrayList<RiakLink>();

}

public class Riak2 {

public static void main(String[] args) throws RiakException {

    IRiakClient client = RiakFactory.httpClient();

    Pojo p = new Pojo();
    p.name = "Pojo"; 
    p.key = "First";
    p.collection.add(new RiakLink("list","Second","next"));

    client.fetchBucket("list").execute().store(p);
}

}

Exception : Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalArgumentException: riak links field must be Collection <RiakLink> at com.basho.riak.client.convert.reflect.AnnotationCache.get(AnnotationCache.java:56)

Please give me a help Thanks

Sameera Kumarasingha
  • 2,908
  • 3
  • 25
  • 41

1 Answers1

1

I've tested this in both the current 1.1.3 and 1.4.2 versions of the client and can not reproduce this issue.

In addition, there's actually a unit test that ensures this works.

Looking though the history for AnnotationCache, I can't find where there was ever a bug regarding this since it was created about two years ago so that rules out you using an old version of the client that has a bug.

Given that, I would suggest rebuilding your project / rechecking that the code you list in your Q is what is actually being used. As shown, there's no problem with it.

Brian Roach
  • 76,169
  • 12
  • 136
  • 161
  • oops..! thanx it works. I might used an older client and it didn't even compiled unit test. I switched to "http://riak-java-client.s3.amazonaws.com/riak-client-1.4.2-jar-with-dependencies.jar" and it works perfectly. Thanks... Again.. – Sameera Kumarasingha Oct 19 '13 at 19:43
  • Actually i just figured out what happened, it was my mistake. the problem was there are 3 RiakLinks & I was using the com.basho.riak.client.http.RiakLink but no errors with com.basho.riak.client.RiakLink – Sameera Kumarasingha Oct 20 '13 at 03:53