[JIRA] (HHH-15657) @ManyToOne(optional = false) + @NotFound(IGNORE) should be flagged as invalid on startup
by Yoann Rodière (JIRA)
Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYzg2M2ZiYTZm... ) / Improvement ( https://hibernate.atlassian.net/browse/HHH-15657?atlOrigin=eyJpIjoiYzg2M2... ) HHH-15657 ( https://hibernate.atlassian.net/browse/HHH-15657?atlOrigin=eyJpIjoiYzg2M2... ) @ManyToOne(optional = false) + @NotFound(IGNORE) should be flagged as invalid on startup ( https://hibernate.atlassian.net/browse/HHH-15657?atlOrigin=eyJpIjoiYzg2M2... )
Issue Type: Improvement Affects Versions: 5.6.12, 6.1.5 Assignee: Unassigned Components: hibernate-core Created: 02/Nov/2022 06:30 AM Priority: Major Reporter: Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Hibernate ORM will currently allow such a mapping:
@JoinColumn(name = "category_id", nullable = false)
@ManyToOne(optional = false)
@NotFound(action = NotFoundAction.IGNORE) // to support operation with default category (id = 0)
private Category category;
The association is marked as non-optional, but then @NotFound is used because some foreign keys don’t point to anything, which means the association is, in fact, optional.
There is clearly a contradiction in this mapping, so Hibernate ORM should probably reject it on startup.
Currently (ORM 5.6.12.Final, 6.1.5.Final, and 6.2.0-SNAPSHOT), Hibernate ORM will accept this mapping, but will then fail to load any entity that has such a “not found” association, simply returning null for such entities when calling session.get or session.multiLoad. Which is not very useful.
See also https://hibernate.zulipchat.com/#narrow/stream/132094-hibernate-orm-dev/t... ( https://hibernate.zulipchat.com/#narrow/stream/132094-hibernate-orm-dev/t... )
( https://hibernate.atlassian.net/browse/HHH-15657#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15657#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100210- sha1:cad9577 )
1 year, 10 months