I would suggest introducing FunctionalJava's Option
in the accessors (getter and setter), while leaving Hibernate to handle a simple java field which is allowed to be null
.
For example, for an optional Integer
field:
// SQL
CREATE TABLE `JKL` (
`JKL_ID` INTEGER PRIMARY KEY,
`MY_FIELD` INTEGER DEFAULT NULL
)
You can map a Hibernate private field directly:
// Java
@Column(nullable = true)
private Integer myField;
You could then introduce Option
at the accessor boundary:
// Java
public fj.data.Option<Integer> getMyField() {
return fj.data.Option.fromNull(myField);
}
public void setMyField(fj.data.Option<Integer> value) {
myField = value.toNull();
}
Does that work for your needs?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…