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.
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
hibernate 4.2.7, mysql 5.6.19, spring-data-jpa 1.3.4.RELEASE