1 Reply Latest reply on Jul 4, 2012 4:30 PM by Greybird-Oracle

    Composite keys

      I'm doing a class with a composite @PrimaryKey ex:

      public class NewsKey {
           @KeyField(1) Long datetime;
           @KeyField(2) String ccy;

      public class News {
           private NewsKey newsKey;

      I have a PrimaryIndex for this key:

      PrimaryIndex<NewsKey, News> newsByKey = mystore.getPrimaryIndex(NewsKey.class, News.class);

      When I do the search by this composite key:

      long fromTime = ; // some time number
      long totime = ; // some time number
      NewsKey fromKey = new NewsKey(fromTime, ccy);
      NewsKey toKey = new NewsKey(toTime, ccy);
      boolean fromInclusive = true;
      boolean toInclusive = true;
      newsByKey.entities(fromKey, fromInclusive, toKey, toInclusive);

      The entities returned doesn't take into account the ccy String value.

      But when I invert the order of key fields e.g.

      public class NewsKey {
           @KeyField(1) String ccy;
           @KeyField(2) Long datetime;

      The search returns the correct result doing the search by ccy and by datetime.

      Does the order or @KeyField influence in the results?
        • 1. Re: Composite keys
          Please see the example and explanation at the top of this page:

          Does this clarify things?