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

Unidirectional one-to-many doesn't take care of many side during removal if bytecode enhancement is on

Description

In an unidirectional one-to-many relation, with a join column on many side, Hibernate seems to forget about nulling foreign keys when removing object on 'one' side if entities are instrumented.

In my test-case (please see it attached) there is Garage entity keeping a set of Cars entities. During removal (without bytecode enhancement) of Garage entity, Hibernate issues the following statements:

1 2 3 4 5 6 7 8 9 10 11 12 13 Hibernate: update Car set GARAGE_ID=null where GARAGE_ID=? Hibernate: delete from Garage where id=?

However when entities are instrumented using 'enableLazyInitialization' mode, the first SQL statement is not generated which leads to constraint violation when the delete statement is executed.

In order to run my test-case with bytecode enhancement (which fails), please issue the following command:

1 mvn clean install -P enhancement

A build run without 'enhancement' profile works correctly.

Please note that this happens only when 'enableLazyInitialization' mode is on; other modes doesn't cause this issue.

Environment

None

Status

Assignee

Luis Barreiro

Reporter

Dominik Łeszyk

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

5.2.0

Priority

Major