Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PATCH Failing with OpenJPA [DATAREST-1216] #1575

Open
spring-projects-issues opened this issue Mar 14, 2018 · 0 comments
Open

PATCH Failing with OpenJPA [DATAREST-1216] #1575

spring-projects-issues opened this issue Mar 14, 2018 · 0 comments
Assignees
Labels
in: repository type: bug type: documentation

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Mar 14, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository type: bug type: documentation
Projects
None yet
Development

No branches or pull requests

2 participants