We're updating the issue view to help you get more done. 

@OneToOne association, Nullable check does is not skipped for @NotFound(action = NotFoundAction.IGNORE)

Description

I have 2 entities with the following

Entity A that contains:

1 2 3 @NotFound(action = NotFoundAction.IGNORE) @OneToOne(mappedBy = "a") private B b;

Entity B that contains:

1 2 3 4 5 6 @OneToOne @NotFound(action = NotFoundAction.IGNORE) @JoinTable(name = JOIN_TABLE, joinColumns = @JoinColumn(name = COLUMN_CASE_PRIMARY_KEY), inverseJoinColumns = @JoinColumn(name = COLUMN_CASE_PRIMARY_KEY_SIDE)) private A a;

When I try to persist an object A wth b = null, I got the following exception

1 2 3 4 5 org.hibernate.PropertyValueException: not-null property references a null or transient value : at org.hibernate.engine.internal.Nullability.checkNullability(Nullability.java:92) at org.hibernate.action.internal.AbstractEntityInsertAction.nullifyTransientReferencesIfNotAlready(AbstractEntityInsertAction.java:115) at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:69) at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:623)

A workaround is to disable the nullability validator.

Otherwise, I've found the field b of class A is considered as not nullable. This seems to happen in the OneToOneSecondPass class that do not consider the @NotFound annotation. Then the built property has optional = false and this become nullable = false when the entity model is built.

Environment

5.2.5, H2

Status

Assignee

Andrea Boriero

Reporter

Jeremy Carnus

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.5

Priority

Major