In my Spring BOOT application, I have a User
class and a LoginCreadential
class.
In my User
class, I have:
@OneToOne(fetch = FetchType.LAZY,targetEntity = LoginCredential.class)
@JoinColumn(name = "userID",referencedColumnName = "userID")
@JsonIgnore
private LoginCredential loginCredential;
And in my LoginCraedential
class:
@OneToOne(mappedBy = "loginCredential", fetch = FetchType.LAZY)
User user;
And when I am creating LoginCreadential
through my React.js application like this :
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:8080/login/');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify({ email: this.state.email,passwordHash:this.state.passwordHash }));
I get something like this :
{"userID":65,"passwordHash":"sad","user":null,"email":"aszzzzzzzzzzdasdasd"},
My LoginCreadential
class has two constructors:
LoginCredential()
{
}
public LoginCredential(String eMail, String passwordHash,User user)
{
this.eMail=eMail;
this.passwordHash=passwordHash;
this.user=user;
}
In my LoginCredentialController
class, I have :
@PostMapping("/login")
void newLoginCredential(@RequestBody LoginCredential newLoginCredential)
{
List<LoginCredential> userList=repository.findByEmailAddress(newLoginCredential.getEMail());
if(userList==null || userList.size()==0)
repository.save(newLoginCredential);
}
The user is always null, shouldn't it create an empty User
or something like this ?
If not how can I achieve it?