spring-projects / spring-projects/spring-data-rest
PATCH Failing with OpenJPA [DATAREST-1216]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Josh Hays opened DATAREST-1216 and commented
PATCH does not work with spring-data-jpa and openjpa. I found a workaround for DELETE using a custom converter:
@Component
public class OpenJpaStringIdConverter implements Converter<StringId, String> {
private static final Logger LOG = LoggerFactory.getLogger(OpenJpaStringIdConverter.class);
@Override
public String convert(StringId source) {
if (LOG.isDebugEnabled()) {
LOG.debug("OpenJpaStringIdConverter - convert: StringId={} to String={}", source, source.getId());
}
return source.getId();
}
}
The converter is added this way:
@Configuration
public class RestConfiguration extends RepositoryRestConfigurerAdapter {
private static final Logger LOG = LoggerFactory.getLogger(RestConfiguration.class);
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.exposeIdsFor(new Class[] { Operator.class, Device.class, Flight.class, Message.class, Tail.class });
}
@Override
public void configureConversionService(ConfigurableConversionService conversionService) {
super.configureConversionService(conversionService);
if (LOG.isDebugEnabled()) {
LOG.debug("Adding custom converter for org.apache.openjpa.util.StringId to java.lang.String");
}
conversionService.addConverter(new OpenJpaStringIdConverter());
}
}
There seems to be a different mechanism for PATCH and PUT within the following class:
org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver
Am I missing something simple, or does this not work as intended?
The exception is as follows:
ERROR o.s.d.r.w.RepositoryRestExceptionHandler - Cannot cast org.apache.openjpa.util.StringId to java.lang.String
Affects: 2.6.10 (Ingalls SR10)
Reference URL: https://stackoverflow.com/questions/49244526/patch-and-delete-failing-with-spring-data-jpa-and-openjpa
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.