I'm exposing my Entity classes with spring-data-rest and spring-data-jpa without difining any custom controllers.
@Entity
public class Domain {
@Id
private String domainName;
Domain(String name) {
this.domainName = name;
}
private Domain() { }
}
Say I want to create a Domain with id stackoverflow.com
, what should I pass in the request body?
Say the Domain resource is exposed at the endpoint /domains
. The reason I'm setting @Id to an String is that I want to be able to retrive a domain by GET /domains/{domainName}
Update
When sending a POST request as follows:
POST /domains
{
"domainName": "stackoverflow.com"
}
I get the exception:
JpaSystemException: ids for this class must be manually assigned before calling save(): space.linuxdeveloper.Network; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): space.linuxdeveloper.Network] with root cause