Skip to content

PATCH Failing with OpenJPA [DATAREST-1216] #1575

Open
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions