1
是否有可能在hibernate
在其中你有兩個領域,其中任何可能爲空,但至少一個用例模型他們不能爲空?下面是我此刻的代碼,但我不喜歡這樣的事實,我有他們兩個設置爲@Column(nullable = true)
。在我來說,我想無論是個人電子郵件地址或工作地址。有沒有一種好的方法來支持這個?還是需要一種替代方法?休眠 - 無論是場A或B可以爲空,但A的一個或B不能爲空
public class ApplicantDetails {
//...
@OneToOne(optional = false)
private ContactDetails contactDetails;
//...
}
public class ContactDetails {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
/*Need at least one email address but it doesn't matter which one.*/
@Column(nullable = true, unique = true)
private String personalEmail;
@Column(nullable = true, unique = true)
private String workEmail;
//...
}
看看按位異或運算[http://stackoverflow.com/questions/1991380/what-does-the-operator-do -in-java的(http://stackoverflow.com/questions/1991380/what-does-the-operator-do-in-java) –
@leviClouser怎麼會在這裏幫助? –