Spring Data MongoDB
  1. Spring Data MongoDB
  2. DATAMONGO-287

MongoDocumentBacking fails when updating a backed attribute

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.0 M4
    • Fix Version/s: Backlog
    • Component/s: Cross-store
    • Labels:
      None

      Description

      When updating an Mongo backed attribute

        @RelatedDocument
        @Transient
        private ProductAttributes attributes;
      
      @Document
      public class ProductAttributes
      {
        private Map<String, Object> values;
      ...
      }
      

      the updated values are not persisted in MongoDB in this unit test:

        @Test
        public void testAttributes()
        {
          final Product p = new Product();
          p.setAttribute(FIXED_FOCAL_LENGTH, Integer.valueOf(100));
          transactionalSave(p);
          final Product p2 = productRepository.findOne(p.getId());
          assertNotSame(p, p2);
          assertEquals(Integer.valueOf(100), p2.getAttributes().get(FIXED_FOCAL_LENGTH));
          p.setAttribute(FIXED_FOCAL_LENGTH, Integer.valueOf(50));
          transactionalSave(p);
          final Product p3 = productRepository.findOne(p.getId());
          assertNotSame(p2, p3);
          // fails: expected 50, was 100 
          assertEquals(Integer.valueOf(50), p3.getAttributes().get(FIXED_FOCAL_LENGTH));
          productRepository.delete(p);
        }
      

        Issue Links

          Activity

          Hide
          Reinhard Maier added a comment -

          Setting the attribute to null is also not persisted:

          // final direct attribute update is also lost
          p3.setAttributes(null);
          save(p3);
          final Product p4 = productRepository.findOne(p.getId());
          assertNotSame(p3, p4);
          // fails
          assertNull(p4.getAttributes().get(FIXED_FOCAL_LENGTH));

          Show
          Reinhard Maier added a comment - Setting the attribute to null is also not persisted: // final direct attribute update is also lost p3.setAttributes(null); save(p3); final Product p4 = productRepository.findOne(p.getId()); assertNotSame(p3, p4); // fails assertNull(p4.getAttributes().get(FIXED_FOCAL_LENGTH));
          Hide
          Thomas Risberg added a comment -

          This fails because the cross-store aspect can't weave the Spring Data JPA jar. Since the JPA code is managing the EntityManager this causes a problem. Have created an issue to improve this DATAMONGO-353.

          Show
          Thomas Risberg added a comment - This fails because the cross-store aspect can't weave the Spring Data JPA jar. Since the JPA code is managing the EntityManager this causes a problem. Have created an issue to improve this DATAMONGO-353 .

            People

            • Assignee:
              Thomas Risberg
              Reporter:
              Reinhard Maier
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: