I have a DateInterval class that is annotated using @Embeddable and has two constant fields: startDate and endDate . The DateInterval field may be optional, depending on the persistent class used. If the DateInterval field is optional, both its startDate and endDate must be NULL.
How to implement this using JPA 2 and / or Hibernate?
If I annotated directly the DateInterval fields, as in the following, then ALL DateInterval fields would not be optional, which is clearly not what I want.
@Embeddable class DateInterval { @Column(nullable = false) public Date getStartDate() { } }
I tried the following but did not work.
class Foo { @Embedded @Column(nullable = true) public DateInterval getDateInterval() { } }
Any suggestions? Thanks!
source share