Redis @Reference does not work in Spring Data Redis












0














I am facing issues while implemeting @Reference in Spring Boot + Spring Data Redis. Address is a List in Employee and when I saved the office and home address and I was expecting the data to be saved with the Employee. But data did not get saved and hence unable to search the Address using street.



Employee.java



@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("employees")
public class Employee {
@Id @Indexed
private String id;
private String firstName;
private String lastName;

@Reference
private List<Address> addresses;
}


Address.java



@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("address")
public class Address {
@Id
private String id;
@Indexed
private String street;
private String city;
}


Test class



@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class EmployeeAdressTest extends RepositoryTestSupport{
@Autowired private EmployeeRepository employeeRepository;


@Before
public void setUp() throws JsonProcessingException {
Address home = Address.builder().street("ABC Street").city("Pune").build();
Address offc = Address.builder().street("XYZ Street").city("Pune").build();

Employee employee1 = Employee.builder().firstName("Raj").lastName("Kumar").addresses(Arrays.asList(home, offc)).build();
employeeRepository.save(employee1);


List<Employee> employees = employeeRepository.findByAddresses_Street("XYZ Street");
System.out.println("EMPLOYEE = "+employees);
}

@Test
public void test() {

}
}


Spring Doc:



8.8. Persisting References
Marking properties with @Reference allows storing a simple key reference instead of copying values into the hash itself. On loading from Redis, references are resolved automatically and mapped back into the object, as shown in the following example:

Example 30. Sample Property Reference
_class = org.example.Person
id = e2c7dcee-b8cd-4424-883e-736ce564363e
firstname = rand
lastname = al’thor
mother = people:a9d4b3a0-50d3-4538-a2fc-f7fc2581ee56
Reference stores the whole key (keyspace:id) of the referenced object.


?










share|improve this question





























    0














    I am facing issues while implemeting @Reference in Spring Boot + Spring Data Redis. Address is a List in Employee and when I saved the office and home address and I was expecting the data to be saved with the Employee. But data did not get saved and hence unable to search the Address using street.



    Employee.java



    @Builder
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @RedisHash("employees")
    public class Employee {
    @Id @Indexed
    private String id;
    private String firstName;
    private String lastName;

    @Reference
    private List<Address> addresses;
    }


    Address.java



    @Builder
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @RedisHash("address")
    public class Address {
    @Id
    private String id;
    @Indexed
    private String street;
    private String city;
    }


    Test class



    @RunWith(SpringJUnit4ClassRunner.class)
    @SpringBootTest
    public class EmployeeAdressTest extends RepositoryTestSupport{
    @Autowired private EmployeeRepository employeeRepository;


    @Before
    public void setUp() throws JsonProcessingException {
    Address home = Address.builder().street("ABC Street").city("Pune").build();
    Address offc = Address.builder().street("XYZ Street").city("Pune").build();

    Employee employee1 = Employee.builder().firstName("Raj").lastName("Kumar").addresses(Arrays.asList(home, offc)).build();
    employeeRepository.save(employee1);


    List<Employee> employees = employeeRepository.findByAddresses_Street("XYZ Street");
    System.out.println("EMPLOYEE = "+employees);
    }

    @Test
    public void test() {

    }
    }


    Spring Doc:



    8.8. Persisting References
    Marking properties with @Reference allows storing a simple key reference instead of copying values into the hash itself. On loading from Redis, references are resolved automatically and mapped back into the object, as shown in the following example:

    Example 30. Sample Property Reference
    _class = org.example.Person
    id = e2c7dcee-b8cd-4424-883e-736ce564363e
    firstname = rand
    lastname = al’thor
    mother = people:a9d4b3a0-50d3-4538-a2fc-f7fc2581ee56
    Reference stores the whole key (keyspace:id) of the referenced object.


    ?










    share|improve this question



























      0












      0








      0


      1





      I am facing issues while implemeting @Reference in Spring Boot + Spring Data Redis. Address is a List in Employee and when I saved the office and home address and I was expecting the data to be saved with the Employee. But data did not get saved and hence unable to search the Address using street.



      Employee.java



      @Builder
      @Data
      @AllArgsConstructor
      @NoArgsConstructor
      @RedisHash("employees")
      public class Employee {
      @Id @Indexed
      private String id;
      private String firstName;
      private String lastName;

      @Reference
      private List<Address> addresses;
      }


      Address.java



      @Builder
      @Data
      @AllArgsConstructor
      @NoArgsConstructor
      @RedisHash("address")
      public class Address {
      @Id
      private String id;
      @Indexed
      private String street;
      private String city;
      }


      Test class



      @RunWith(SpringJUnit4ClassRunner.class)
      @SpringBootTest
      public class EmployeeAdressTest extends RepositoryTestSupport{
      @Autowired private EmployeeRepository employeeRepository;


      @Before
      public void setUp() throws JsonProcessingException {
      Address home = Address.builder().street("ABC Street").city("Pune").build();
      Address offc = Address.builder().street("XYZ Street").city("Pune").build();

      Employee employee1 = Employee.builder().firstName("Raj").lastName("Kumar").addresses(Arrays.asList(home, offc)).build();
      employeeRepository.save(employee1);


      List<Employee> employees = employeeRepository.findByAddresses_Street("XYZ Street");
      System.out.println("EMPLOYEE = "+employees);
      }

      @Test
      public void test() {

      }
      }


      Spring Doc:



      8.8. Persisting References
      Marking properties with @Reference allows storing a simple key reference instead of copying values into the hash itself. On loading from Redis, references are resolved automatically and mapped back into the object, as shown in the following example:

      Example 30. Sample Property Reference
      _class = org.example.Person
      id = e2c7dcee-b8cd-4424-883e-736ce564363e
      firstname = rand
      lastname = al’thor
      mother = people:a9d4b3a0-50d3-4538-a2fc-f7fc2581ee56
      Reference stores the whole key (keyspace:id) of the referenced object.


      ?










      share|improve this question















      I am facing issues while implemeting @Reference in Spring Boot + Spring Data Redis. Address is a List in Employee and when I saved the office and home address and I was expecting the data to be saved with the Employee. But data did not get saved and hence unable to search the Address using street.



      Employee.java



      @Builder
      @Data
      @AllArgsConstructor
      @NoArgsConstructor
      @RedisHash("employees")
      public class Employee {
      @Id @Indexed
      private String id;
      private String firstName;
      private String lastName;

      @Reference
      private List<Address> addresses;
      }


      Address.java



      @Builder
      @Data
      @AllArgsConstructor
      @NoArgsConstructor
      @RedisHash("address")
      public class Address {
      @Id
      private String id;
      @Indexed
      private String street;
      private String city;
      }


      Test class



      @RunWith(SpringJUnit4ClassRunner.class)
      @SpringBootTest
      public class EmployeeAdressTest extends RepositoryTestSupport{
      @Autowired private EmployeeRepository employeeRepository;


      @Before
      public void setUp() throws JsonProcessingException {
      Address home = Address.builder().street("ABC Street").city("Pune").build();
      Address offc = Address.builder().street("XYZ Street").city("Pune").build();

      Employee employee1 = Employee.builder().firstName("Raj").lastName("Kumar").addresses(Arrays.asList(home, offc)).build();
      employeeRepository.save(employee1);


      List<Employee> employees = employeeRepository.findByAddresses_Street("XYZ Street");
      System.out.println("EMPLOYEE = "+employees);
      }

      @Test
      public void test() {

      }
      }


      Spring Doc:



      8.8. Persisting References
      Marking properties with @Reference allows storing a simple key reference instead of copying values into the hash itself. On loading from Redis, references are resolved automatically and mapped back into the object, as shown in the following example:

      Example 30. Sample Property Reference
      _class = org.example.Person
      id = e2c7dcee-b8cd-4424-883e-736ce564363e
      firstname = rand
      lastname = al’thor
      mother = people:a9d4b3a0-50d3-4538-a2fc-f7fc2581ee56
      Reference stores the whole key (keyspace:id) of the referenced object.


      ?







      spring redis jedis spring-data-redis






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 15:02

























      asked Nov 20 at 5:11









      PAA

      2,46721935




      2,46721935





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386600%2fredis-reference-does-not-work-in-spring-data-redis%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386600%2fredis-reference-does-not-work-in-spring-data-redis%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy