这是场景:
我有两个实体
@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
,Footer
和Header
。
我创建了一个Project
包含三个模块的集合:
{
"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