0

Currently I am struggling with PUT, I always get 500 Request Failed.

Screenshot of the Problem

User

    {"id": 3,
    "firstname": "lmao",
    "lastname": "test",
    "username": "test",
    "password": "test",
    "created": "2018-08-12",
    "locks": []
    }

Source

@PUT
@Path("user/{id}")
@Consumes(MediaType.APPLICATION_JSON)
public void editUser(@PathParam("id") int id, User u) {
    long i = (long) id;
    u.setId(i);
    rep.updateUser(u);
}

Repository

public void updateUser(User u) {
    User user = (User) em.find(User.class, u.getId());
    if (user != null) {
        user = u;
        em.getTransaction().begin();
        em.refresh(user);
        em.getTransaction().commit();
    }
}
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • add your stacktrace error – GolamMazid Sajib Aug 12 '18 at 14:45
  • and where is the problem ? In your REST ? or in the JPA code? Because debugging such things should be the first thing you do, to narrow it down ... There is no such thing as "JPA REST" –  Aug 12 '18 at 14:46
  • In my REST Service, the only error I get is the on in Insomnia, thats why I am looking for help here. – yung Hustler Aug 12 '18 at 14:56
  • `Http Status 500` indicates server issue or application is not properly deployed. – Ravi Aug 12 '18 at 15:12
  • I would recommend to use Respository, which extends ``CrudRepository`` . In Controller, you should have ``@RequestBody`` for object ``User`` – BlackPearl Aug 12 '18 at 15:13
  • Register [this DebugMapper](https://stackoverflow.com/a/45758691/2587435) with your application then run the request again. See if you get a stack trace. If you do, please post it. And also show your `User` class – Paul Samsotha Aug 13 '18 at 08:00

0 Answers0