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

HTTP PUT doesn't do update, but new #250

Closed
bashekking opened this issue Sep 4, 2014 · 5 comments
Closed

HTTP PUT doesn't do update, but new #250

bashekking opened this issue Sep 4, 2014 · 5 comments

Comments

@bashekking
Copy link

HTTP PUT doesn't seem to work ok with PagingAndSortingRepository.
Not in my code (see below) but also not in spring-boot-sample-rest code (spring-projects/spring-boot#1514)

When I try to do an update with HTTP PUT of a simple json object 'brand', a new brand is created.
I use only a standard respository (see below) with a simple brand model (see below). When I do an update in code using the repository, the brand is actually modified.

Any help would be really appreciated, i'm breaking my head over this

My curl output (the field 'Location: http://localhost:8181/brands/13' shows that a new brand is created):

$ curl -v -X PUT -d '{"name":"Alibastine"}' -H "Content-Type: application/json" http://localhost:8181/brands/1

  • Hostname was NOT found in DNS cache
  • Trying 127.0.0.1...
  • Connected to localhost (127.0.0.1) port 8181 (#0)

    PUT /brands/1 HTTP/1.1
    User-Agent: curl/7.35.0
    Host: localhost:8181
    Accept: /
    Content-Type: application/json
    Content-Length: 21

  • upload completely sent off: 21 out of 21 bytes
    < HTTP/1.1 204 No Content
  • Server Apache-Coyote/1.1 is not blacklisted
    < Server: Apache-Coyote/1.1
    < Access-Control-Allow-Origin: *
    < Access-Control-Allow-Headers: X-Requested-With, Origin, Content-Type, Accept
    < Location: http://localhost:8181/brands/13
    < Date: Thu, 04 Sep 2014 17:33:10 GMT

BrandRepository.java:
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.history.RevisionRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import com.builder.ws.models.entities.Brand;

@RepositoryRestResource(collectionResourceRel = "brands", path = "brands")
public interface BrandRepository extends PagingAndSortingRepository<Brand, Long>
{
}

Brand.java:
import java.net.URL;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Table;
import javax.validation.constraints.Size;

@entity
public class Brand {
@id
@GeneratedValue
public Long id;

@Column(nullable = false)
@Size(min = 2, max = 30)
private String name;

public Brand(){

}

public Brand(String name){
    this.name=name;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

}

Regards,

Bas

@gregturn
Copy link
Contributor

gregturn commented Sep 5, 2014

  1. Your repository definition doesn't have the generics plugged in, so I don't know if that's your real code or something hastily pasted into this ticket.
  2. There is no information about the versions of things you used.

But given that I was able to take your domain objects, use Spring Boot 1.1.6.RELEASE (which uses the latest release of Spring Data REST + HATEOAS) and see everything work properly in https://github.com/gregturn/brands, I don't think this is an issue.

@bashekking
Copy link
Author

Thanks a lot!! Your code works, and i'll try to find the differences and post them here.

@marcosjunqueira
Copy link

I'm with the same problem but using spring platform, maybe it's a problem with dependencies
http://docs.spring.io/platform/docs/1.0.3.RELEASE/reference/htmlsingle/#appendix-dependency-versions

@marcosjunqueira
Copy link

This problem occurs when i use domainClassConverter, if i remove this code it works perfectly.

    @Bean
    public FormattingConversionService mvcConversionService() {
        FormattingConversionService conversionService = new DefaultFormattingConversionService();
        addFormatters(conversionService);
        return conversionService;
    }

    @Bean
    public DomainClassConverter<?> domainClassConverter() {
        return new DomainClassConverter<FormattingConversionService>(mvcConversionService());
    }

@gregturn
Copy link
Contributor

gregturn commented Jun 5, 2020

Based upon spring-projects/spring-boot#1514 and https://github.com/gregturn/brands, this issue is deemed invalid.

Regarding the newly added issue, please open a new ticket if you are still having issues. It's hard to sort out two unrelated things in one ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants