Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-711

DomainClassConverter triggered unnecessarily

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 1.10 GA (Fowler)
    • Fix Version/s: 1.10.1 (Fowler SR1)
    • Component/s: Integration
    • Labels:

      Description

      DomainClassConverter wrongfully triggers on form submits. I have a controller, which accepts a filled out Entity as a form

      @RequestMapping(value="entity/edit", method=RequestMethod.POST)
      public String modifyEntity(@Validated(Edit.class) Entity entity){

      MVC builds a Detached Entity, and does a check if a conversion via the ConversionService must take place. The conversion goes from com.mycompany.myproject.domain.Entity to @Validated com.mycompany.myproject.domain.Entity. It goes through every registered converter to see if someone wishes to perform this conversion. So far so good.

      Now DomainClassConverter.ToIdConverter checks if it can convert Entity to @Validated Entity. It agrees that it can not, however it then reduces the source entity to its ID, and begins a brand new search by the converters to see if Entity's String id can be converted to Entity. Of course it finds – the DomainClassConverter.ToEntityConverter.

      Thus the DomainClassConvert.ToIdConverter is found as a legitimate converter for Entity->@Validated Entity. When it is asked to do this convertion, it doesn't match them as equals, being as they have different annotations, and actually invokes DomainClassConvert.ToEntityConverter which does a callback to the database etc. etc. etc.

      There are of course two problems with this. Most importantly, it discards any of the changes. Secondly, since my Entity has a collection, and the DomainClassConverter loads the Entity in its own transaction, which is commited and closed by the time the Controller is called, any work on the collection results in a org.hibernate.LazyInitializationException.

      Basically, I am now disabling DomainClassConverter, until this is fixed. I think the way to fix it, is to do more intelligent TypeDescriptor comparisons in the convert method. Alternatively, some way to disable DomainClassConverter from activating on a specific controller, or just only focusing on IdToEntity, and never EntityToId

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              doom777 doom777
              Last updater:
              Oliver Drotbohm
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 1d
                  1d
                  Remaining:
                  Remaining Estimate - 1d
                  1d
                  Logged:
                  Time Spent - Not Specified
                  Not Specified