title: Ids for this class must be manually assigned before calling save on String ID
body: <p>Already read lots of questions about the same issue, but I still not be able to solve this problem.</p>
  
  <p>I need to have a <code>String</code> primary key on my database.</p>
  
  <pre><code>import javax.persistence.Entity;
  import javax.persistence.Id;
  
  @Entity
  public class MyClass {
  
      @Id
      private String myId;
      private String name;
  
      // getters and setters..
  
  }
  </code></pre>
  
  <p>The problem is that, if I use <code>String</code> type in a <code>@Id</code> annotated field, Hibernate throws an exception when I try to save the object.</p>
  
  <pre><code>ids for this class must be manually assigned before calling 
  </code></pre>
  
  <p>And yes, I'm setting a value to the field.</p>
  
  <p>Workarounds I found:</p>
  
  <ol>
  <li>Add <code>@GeneratedValue</code> annotation to the field - not worked</li>
  <li>Change the field type to <code>Integer</code> - it's not feasible for me</li>
  <li>Add a constructor that receives <code>myId</code> as parameter <code>public MyClass(String myId){ ... }</code> - not worked</li>
  <li>Use UUID - i can't, cause this id is set by a field that comes in with a POST request.</li>
  </ol>
  
  <p>None of these workarounds worked for me.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I'm using Spring Boot and Spring Data JPA.</p>
  
  <p>How do I insert:</p>
  
  <p>I have an <code>@PostMapping</code> annotated method which handles POST request and call a service that do some business logic and call my repository for persisting.</p>
  
  <p>The request I post:</p>
  
  <pre><code>{
      "myId": "myId",
      "name": "myName"
  }
  </code></pre>
  
  <p><strong>MyService.java</strong></p>
  
  <pre><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  @Service
  public class MyService {
  
      @Autowired
      private MyRepository myRepository;
  
      public MyClass save(MyClass myClass) {
          return myRepository.save(myClass); // save() should persist my object into the database
      }
  }
  </code></pre>