0

シナリオは次のとおりです。

2つのエンティティを取得しました

@Entity
@Data
class Project {

    @NotEmpty
    private String name;

    @OneToMany(cascade=ALL, orphanRemoval=true)
    @JoinColumn(name="project")
    private List<Module> modules = new ArrayList<>();
}

@Entity
class Module {

    @NotEmpty
    String content;

    @ManyToOne
    @JoinColumn(name="project")
    private Project project;
}

Articleモジュールには 、 、の 3 種類がありFooterますHeader

Project3 つのモジュールの with コレクションを作成します。

{
  "name" "Test project",
  "modules" : [
    { "type": "Header", "content": "Test title" },
    { "type": "Article", "content": "Bad news!" },
    { "type": "Footer", "content": "Test contact" }
  ]
}

私はPOSTそれの下に/projectsあり、おかげ@RepositoryRestResourceですべてがうまく機能します。Project-Test projectの下で利用できるようになりまし/projects/1た。

しかし今、私がPUTデータ/projects/1を扱うとき

{
  "name" "Real test project",
  "modules" : [
    { "type": "Header", "content": "Better title" },
    { "type": "Article", "content": "Good news!" },
    { "type": "Article", "content": "Even better news!" },
    { "type": "Article", "content": "Wonderful news!" },
    { "type": "Footer", "content": "phone (00000)" }
  ]
}

それはいつもで終わる

org.springframework.http.converter.HttpMessageNotReadableException: Could not read an object of type class com.example.Project from the request!; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: Could not read payload!; nested exception is java.lang.IllegalArgumentException: Target bean of type com.example.Article is not of type of the persistent entity (com.example.Footer)!
    at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.readPutForUpdate(PersistentEntityResourceHandlerMethodArgumentResolver.java:228) ~[spring-data-rest-webmvc-2.6.9.RELEASE.jar:na]
    at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.read(PersistentEntityResourceHandlerMethodArgumentResolver.java:194) ~[spring-data-rest-webmvc-2.6.9.RELEASE.jar:na]
    at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.resolveArgument(PersistentEntityResourceHandlerMethodArgumentResolver.java:141) ~[spring-data-rest-webmvc-2.6.9.RELEASE.jar:na]
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:158) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:883)

編集

問題はすでに調査されているようですhttps://jira.spring.io/browse/DATAREST-1012

4

0 に答える 0