[hibernate-dev] https://hibernate.atlassian.net/browse/HHH-9798 Unique constraint / not null of @JoinTable for @OneToOne not generated
Jason Pyeron
jpyeron at pdinc.us
Sun Apr 19 11:19:41 EDT 2020
I think I have found another corner case on the https://hibernate.atlassian.net/browse/HHH-9798 regression.
The cited example is:
@OneToOne(fetch = FetchType.LAZY)
@JoinTable(
name = "ITEM_SHIPMENT", // Required!
joinColumns =
@JoinColumn(name = "SHIPMENT_ID"), // Defaults to ID
inverseJoinColumns =
@JoinColumn(name = "ITEM_ID", // Defaults to AUCTION_ID
nullable = false,
unique = true)
)
protected Item auction;
but an equally similar case ought to be:
@OneToOne(fetch = FetchType.LAZY)
@JoinTable(
name = "ITEM_SHIPMENT", // Required!
)
protected Item auction;
The rationale here is that a @JoinTable is used to “not have the null rows” that would be present if a @JoinColumn was to be used on an @OneToOne(optional=true). I cannot find in the spec where this is implied, required, or excluded.
Otherwise one would have to say:
@OneToOne(fetch = FetchType.LAZY)
@JoinTable(
name = "ITEM_SHIPMENT", // Required!
inverseJoinColumns =
@JoinColumn(nullable = false,
unique = true)
)
protected Item auction;
Thoughts?
-Jason
More information about the hibernate-dev
mailing list