I'm trying to persist a User that has a mapping @ManyToOne with UserStatus
but when I do the code below, the hibernate throws PropertyValueException
user.setStatus(new UserStatus(1));
em.persist(user); // ou session.saveAndUpdate(user);
to work I have to do this way:
user.setStatus(em.getReference(UserStatus.class, 1));
em.persist(user); // ou session.saveAndUpdate(user);
I know the first way is possible, but what I don't know is whether I need to configure or call another method (I've already tried saveAndUpdate from Session and still the same)
Does anyone have any idea?
The error message is:
not-null property references a null or transient value
the mapping
@ManyToOne(optional = false)
@JoinColumn(name = "user_status_id", nullable = false)
public UserStatus getStatus() {
return status;
}