Lifecycle Events on ManyToMany References Do Not Fire On Cascades

Description

I have setup a ManyToMany relationship for User/Groups and have cascading set to MERGE and PERSIST. I have a listener registered to add audit data to my tables on persist and update via the lifecycle events to help keep the code clean.

When adding a reference to the many to many set, the cascading appears to take effect, as expected, as I see an insert on the intermediate reference table between users and groups (debug logs with show_sql). However, the lifecycle events are not triggering, as I do not have the audit data present in the insert statement, resulting in a null constraint violation. I have stepped through the code execution with a debugger and do not catch my breakpoint when the intermediate reference table insert statement occurs and the exception is thrown.

Auditable

AuditListener

User

Group

UserGroup

UserGroupId

Intended usage

I am seeing these sql statments:

And this results on the null constraint violation

I'd expect this:

Again, it looks like the cascade is working, since the insert on UserGroup gets sent, however, the AuditListener's @PrePersist method is not getting called

Environment

hibernate 4.2.7, mysql 5.6.19, spring-data-jpa 1.3.4.RELEASE

Assignee

Unassigned

Reporter

Joey Yore

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure