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

ReflectionRepositoryInvoker should accept repositories with findOne(…) method only

    XMLWordPrintable

    Details

      Description

      When doing a post on a resource with a many-to-one association:

      • Resource to create is of type DataCollectionPeriod
      • The payload of the POST is: { "year": "2014", "country": "http://localhost:8080/api/countries/100200" } I get the following error message: {code}

        Caused by: java.lang.IllegalArgumentException: Repository class com.sun.proxy.$Proxy76 does not expose a save method!
        at org.springframework.util.Assert.isTrue(Assert.java:65)
        at org.springframework.data.repository.support.ReflectionRepositoryInvoker.<init>(ReflectionRepositoryInvoker.java:53)
        at org.springframework.data.repository.support.Repositories.getCrudInvoker(Repositories.java:206)
        at org.springframework.data.repository.support.DomainClassConverter.convert(DomainClassConverter.java:71)
        at org.springframework.data.rest.core.UriToEntityConverter.convert(UriToEntityConverter.java:111)
        at org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$UriStringDeserializer.deserialize(PersistentEntityJackson2Module.java:390)
        at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:525)
        at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:99)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:242)

        This is because my CountryRepository only implemented the Repository<T,ID> interface. If I change it to extend CrudRepository<T,ID>, this problem does not occur.
        
        As I am not updating the Country resource but just associating to another resource, I believe that it should not be necessary to provide a save method.
        
        For information:
        
        {code:title=DataCollectionPeriod.java  (details are omitted)|borderStyle=solid}
        @Entity
        public class DataCollectionPeriod extends AggregateEntity {
        
        	@Id
        	private Long id;
        
        	@Column(name="YEAR", nullable=false)
        	private int year;
        
        	@ManyToOne
        	@JoinColumn(name="COUNTRY_ID", nullable=false)
        	private Country country;
        }
        
        

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              adelinor Adelino Rodrigues
              Last updater:
              Oliver Drotbohm
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: