Spring Boot
version 2.1.6
.
I have User
class :
@Data
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
Long userID;
String eMail;
public User()
{
}
}
And a LoginCredential
class :
@Data
@Entity
public class LoginCredential {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
Long userID;
String eMail;
String passwordHash;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "id", referencedColumnName = "id")
User user;
public LoginCredential()
{
}
}
Shouldn't it create an instance of User
when I create an instance of LoginCredential
.
Cause I run this command : curl -X POST -H "Content-Type: application/json" -d "{ \"email\": \"a\", \"passwordHash\": \"b\" }" http://localhost:8080/login
And I got an instance of LoginCredential
but not of an User
.
Response :
{"userID":1,"passwordHash":"b","user":null,"email":"a"}
And then I run this command : curl -X POST -H "Content-Type: application/json" -d "{ \"email\": \"c\", \"passwordHash\": \"d\" ,\"user\":{}}" http://localhost:8080/login
And what I got is nothing, not of same ID.
Response :
{"userID":2,"passwordHash":"d","user":{"userID":3,"email":null},"email":"c"}
Am I missing something ? How this can be resolved ?
LoginCredentialController
partially :
@PostMapping("/login")
LoginCredential newLoginCredential(@RequestBody LoginCredential newLoginCredential)
{
return repository.save(newLoginCredential);
}
My pom.xml