i have a table called user which has a PK on column usernmae (varchar) and a colum referer (varchar) that is a FK pointing to username (same table)
i want to add a new user entity (DB row) and make sure the referer is not null and pointing to an existing user PK (username)
Code:
@Id
@OneToOne
@NotNull
@Column(name="username")
public String getUserName() {return userName;}
public void setUserName(String userName) {this.userName = userName;}
@OneToOne
@JoinColumn(name="referer")
public User getReferer() {return referer;}
public void setReferer(User referer) {this.referer = referer;}
solved , but i have another q. can i make hibernate validate that the @Id is unique and not fail on constraint violation ?