<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <base href="https://hibernate.atlassian.net" />
<title>Message Title</title>
</head>
<body class="jira" style="color: #333; font-family: Arial, sans-serif; font-size: 14px; line-height: 1.429">
<table id="background-table" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #f5f5f5; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<!-- header here -->
<tr>
<td id="header-pattern-container" style="padding: 0px; border-collapse: collapse; padding: 10px 20px">
<table id="header-pattern" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tr>
<td id="header-avatar-image-container" valign="top" style="padding: 0px; border-collapse: collapse; vertical-align: top; width: 32px; padding-right: 8px"> <img id="header-avatar-image" class="image_fix" src="https://secure.gravatar.com/avatar/fcd75316c02b0cdb60ed7321613764bb?d=mm&s=48" height="32" width="32" border="0" style="border-radius: 3px; vertical-align: top" />
</td>
<td id="header-text-container" valign="middle" style="padding: 0px; border-collapse: collapse; vertical-align: middle; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> <a class="user-hover" rel="jyore" id="email_jyore" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=jyore" style="color:#6c797f;; color: #3b73af; text-decoration: none">Joey Yore</a> <strong>created</strong> an issue
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td id="email-content-container" style="padding: 0px; border-collapse: collapse; padding: 0 20px">
<table id="email-content-table" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; border-spacing: 0; border-collapse: separate">
<tr>
<!-- there needs to be content in the cell for it to render in some clients -->
<td class="email-content-rounded-top mobile-expand" style="padding: 0px; border-collapse: collapse; color: #fff; padding: 0 15px 0 16px; height: 15px; background-color: #fff; border-left: 1px solid #ccc; border-top: 1px solid #ccc; border-right: 1px solid #ccc; border-bottom: 0; border-top-right-radius: 5px; border-top-left-radius: 5px; height: 10px; line-height: 10px; padding: 0 15px 0 16px; mso-line-height-rule: exactly">
</td>
</tr>
<tr>
<td class="email-content-main mobile-expand " style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #fff">
<table class="page-title-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tr>
<td class="page-title-pattern-first-line " style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; padding-top: 10px"> <a href="https://hibernate.atlassian.net/browse/HHH" style="color: #3b73af; text-decoration: none">Hibernate ORM</a> / <a href="https://hibernate.atlassian.net/browse/HHH-9429" style="color: #3b73af; text-decoration: none"><img src="cid:jira-generated-image-static-bug-7c87e2a0-e1a3-45cb-bd65-59dc23589862" height="16" width="16" border="0" align="absmiddle" alt="Bug" style="vertical-align: text-bottom" /></a> <a href="https://hibernate.atlassian.net/browse/HHH-9429" style="color: #3b73af; text-decoration: none">HHH-9429</a>
</td>
</tr>
<tr>
<td style="vertical-align: top;; padding: 0px; border-collapse: collapse; padding-right: 5px; font-size: 20px; line-height: 30px; mso-line-height-rule: exactly" class="page-title-pattern-header-container"> <span class="page-title-pattern-header" style="font-family: Arial, sans-serif; padding: 0; font-size: 20px; line-height: 30px; mso-text-raise: 2px; mso-line-height-rule: exactly; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HHH-9429" style="color: #3b73af; text-decoration: none">Lifecycle Events on ManyToMany References Do Not Fire On Cascades</a> </span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="email-content-main mobile-expand wrapper-special-margin" style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #fff; padding-top: 10px; padding-bottom: 5px">
<table class="keyvalue-table" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tr>
<th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">
Issue Type:
</th>
<td class="has-icon" style="padding: 0px; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> <img src="cid:jira-generated-image-static-bug-7c87e2a0-e1a3-45cb-bd65-59dc23589862" height="16" width="16" border="0" align="absmiddle" alt="Bug" style="vertical-align: text-bottom" /> Bug
</td>
</tr>
<tr>
<th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">
Affects Versions:
</th>
<td style="padding: 0px; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top">
4.2.7.SP1
</td>
</tr>
<tr>
<th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">
Assignee:
</th>
<td style="padding: 0px; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top">
Unassigned
</td>
</tr>
<tr>
<th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">
Components:
</th>
<td style="padding: 0px; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top">
core
</td>
</tr>
<tr>
<th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">
Created:
</th>
<td style="padding: 0px; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top">
03/Oct/2014 12:00 PM
</td>
</tr>
<tr>
<th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">
Environment:
</th>
<td style="padding: 0px; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top">
hibernate 4.2.7, mysql 5.6.19, spring-data-jpa 1.3.4.RELEASE
</td>
</tr>
<tr>
<th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">
Priority:
</th>
<td class="has-icon" style="padding: 0px; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> <img src="cid:jira-generated-image-static-major-c1773ea1-f9b6-490b-a8b0-02666360bddf" height="16" width="16" border="0" align="absmiddle" alt="Major" style="vertical-align: text-bottom" /> Major
</td>
</tr>
<tr>
<th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">
Reporter:
</th>
<td style="padding: 0px; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> <a class="user-hover" rel="jyore" id="email_jyore" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=jyore" style="color:#6c797f;; color: #3b73af; text-decoration: none">Joey Yore</a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="email-content-main mobile-expand issue-description-container" style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #fff; padding-top: 5px; padding-bottom: 10px">
<table class="text-paragraph-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 2px">
<tr>
<td class="text-paragraph-pattern-container mobile-resize-text " style="padding: 0px; border-collapse: collapse; padding: 0 0 10px 0">
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">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.</p>
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">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.</p>
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">Auditable</p>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">
<span class="code-keyword" style="color: #000091">public</span> <span class="code-keyword" style="color: #000091">interface</span> Auditable {
void setTouchedBy(<span class="code-object" style="color: #910091">String</span> touchedBy);
void setTouchedAt(Date touchedAt);
void setCreatedBy(<span class="code-object" style="color: #910091">String</span> createdBy);
void setCreatedAt(<span class="code-object" style="color: #910091">String</span> createdAt);
}
</pre>
</div>
</div>
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">AuditListener</p>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">
<span class="code-keyword" style="color: #000091">public</span> AuditListener {
@PrePersist
<span class="code-keyword" style="color: #000091">public</span> void onPrePersist(Auditable entity) {
Date date = <span class="code-keyword" style="color: #000091">new</span> Date();
<span class="code-object" style="color: #910091">String</span> user = getUser();
entity.setTouchedBy(user);
entity.setTouchedAt(date);
entity.setCreatedBy(user);
entity.setCreatedAt(date);
}
@PreUpdate
<span class="code-keyword" style="color: #000091">public</span> void onPreUpdate(Auditable entity) {
Date date = <span class="code-keyword" style="color: #000091">new</span> Date();
<span class="code-object" style="color: #910091">String</span> user = getUser();
entity.setTouchedBy(user);
entity.setTouchedAt(date);
}
<span class="code-comment" style="color: #808080">//Get username from spring-security
</span> <span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> getUser() {
Authentication auth = SecurityContextHolder.getContext().getAutnetication();
<span class="code-keyword" style="color: #000091">if</span>(auth != <span class="code-keyword" style="color: #000091">null</span>) {
<span class="code-object" style="color: #910091">Object</span> principal = auth.getPrincipal();
<span class="code-keyword" style="color: #000091">if</span>(principal isinstance <span class="code-object" style="color: #910091">String</span>) {
<span class="code-keyword" style="color: #000091">return</span> principal.toString();
} <span class="code-keyword" style="color: #000091">else</span> {
<span class="code-keyword" style="color: #000091">return</span> ((UserDetails) principal).getUsername();
}
}
<span class="code-keyword" style="color: #000091">return</span> <span class="code-quote" style="color: #009100">"unknown"</span>;
}
}
</pre>
</div>
</div>
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">User</p>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">
@Entity
@Table(name=<span class="code-quote" style="color: #009100">"user"</span>)
@EntityListeners(AuditListener.class)
<span class="code-keyword" style="color: #000091">public</span> class User <span class="code-keyword" style="color: #000091">implements</span> Serializable,Auditable {
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">Integer</span> userId;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> username;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> password;
<span class="code-keyword" style="color: #000091">private</span> Date touchedBy;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> touchedAt;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> createdBy;
<span class="code-keyword" style="color: #000091">private</span> Date createdAt;
<span class="code-keyword" style="color: #000091">private</span> Set<UserGroup> userGroups = <span class="code-keyword" style="color: #000091">new</span> HashSet<UserGroups>();
<span class="code-keyword" style="color: #000091">private</span> Set<Group> groups = <span class="code-keyword" style="color: #000091">new</span> HashSet<Group>();
/* snipped constructors <span class="code-keyword" style="color: #000091">for</span> brevity */
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = <span class="code-quote" style="color: #009100">"UserID"</span>,unique = <span class="code-keyword" style="color: #000091">true</span>,nullable = <span class="code-keyword" style="color: #000091">false</span>)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">Integer</span> getId() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.id;
}
@Column(name = <span class="code-quote" style="color: #009100">"Password"</span>, nullable = <span class="code-keyword" style="color: #000091">false</span>)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">String</span> getPassword() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.password;
}
@Column(name = <span class="code-quote" style="color: #009100">"TouchedBy"</span>, nullable = <span class="code-keyword" style="color: #000091">false</span>, length = 50)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">String</span> getTouchedBy() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.touchedBy;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = <span class="code-quote" style="color: #009100">"TouchedAt"</span>, nullable = <span class="code-keyword" style="color: #000091">false</span>, length = 19)
<span class="code-keyword" style="color: #000091">public</span> Date getTouchedAt() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.touchedAt;
}
@Column(name = <span class="code-quote" style="color: #009100">"CreatedBy"</span>, nullable = <span class="code-keyword" style="color: #000091">false</span>, length = 50)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">String</span> getCreatedBy() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.createdBy;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = <span class="code-quote" style="color: #009100">"CreatedAt"</span>, nullable = <span class="code-keyword" style="color: #000091">false</span>, length = 19)
<span class="code-keyword" style="color: #000091">public</span> Date getCreatedAt() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.createdAt;
}
@OneToMany(fetch = FetchType.EAGER, mappedBy = <span class="code-quote" style="color: #009100">"user"</span>)
<span class="code-keyword" style="color: #000091">public</span> Set<UserGroup> getUserGroup() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.userGroups;
}
@ManyToMany(cascade = { CascadeType.MERGE,CascadeType.PERSIST })
@JoinTable(name = <span class="code-quote" style="color: #009100">"UserGroup"</span>,
joinColumns = { @JoinColumn(name = <span class="code-quote" style="color: #009100">"UserId"</span>) },
inverseJoinColumns = { @JoinColumn(name = <span class="code-quote" style="color: #009100">"GroupId"</span>) })
<span class="code-keyword" style="color: #000091">public</span> Set<Group> getGroups() {
<span class="code-keyword" style="color: #000091">return</span> groups;
}
/* Setters snipped <span class="code-keyword" style="color: #000091">for</span> brevity */
}
</pre>
</div>
</div>
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">Group</p>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">
@Entity
@Table(name=<span class="code-quote" style="color: #009100">"group"</span>)
@EntityListener(AuditListener.class)
<span class="code-keyword" style="color: #000091">public</span> class Group <span class="code-keyword" style="color: #000091">implements</span> Serialiable,Auditable {
<span class="code-keyword" style="color: #000091">private</span> Ingeger groupId;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> name;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">Boolean</span> enabled;
<span class="code-keyword" style="color: #000091">private</span> Date touchedBy;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> touchedAt;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> createdBy;
<span class="code-keyword" style="color: #000091">private</span> Date createdAt;
/* snipped permission relationship <span class="code-keyword" style="color: #000091">for</span> brevity */
<span class="code-keyword" style="color: #000091">private</span> Set<UserGroup> userGroups = <span class="code-keyword" style="color: #000091">new</span> HashSet<UserGroups>();
<span class="code-keyword" style="color: #000091">private</span> Set<User> users = <span class="code-keyword" style="color: #000091">new</span> HashSet<User>();
        /* snipped constructors <span class="code-keyword" style="color: #000091">for</span> brevity */
/* snipped the boring getters <span class="code-keyword" style="color: #000091">for</span> brevity */
@OneToMany(fetch = FetchType.EAGER, mappedBy = <span class="code-quote" style="color: #009100">"group"</span>)
<span class="code-keyword" style="color: #000091">public</span> Set<UserGroup> getUserGroup() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.userGroups;
}
@ManyToMany(mappedBy = <span class="code-quote" style="color: #009100">"groups"</span>, cascade = cascade = { CascadeType.MERGE,CascadeType.PERSIST })
<span class="code-keyword" style="color: #000091">public</span> Set<Users> getUsers() {
<span class="code-keyword" style="color: #000091">return</span> users;
}
/* snipped setters <span class="code-keyword" style="color: #000091">for</span> brevity */
}
</pre>
</div>
</div>
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">UserGroup</p>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">
@Entity
@Table(name=<span class="code-quote" style="color: #009100">"usergroup"</span>)
@EntityListener(AuditListener.class)
<span class="code-keyword" style="color: #000091">public</span> class UserGroup <span class="code-keyword" style="color: #000091">implements</span> Serialiable,Auditable {
<span class="code-keyword" style="color: #000091">private</span> UserGroupdId id;
<span class="code-keyword" style="color: #000091">private</span> User user;
<span class="code-keyword" style="color: #000091">private</span> Group group;
<span class="code-keyword" style="color: #000091">private</span> Date touchedBy;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> touchedAt;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">String</span> createdBy;
<span class="code-keyword" style="color: #000091">private</span> Date createdAt;
/* snipped constructors <span class="code-keyword" style="color: #000091">for</span> brevity */
@EmbeddedId
@AttributeOverrides({ @AttributeOverride(name = <span class="code-quote" style="color: #009100">"userId"</span>, column = @Column(name = <span class="code-quote" style="color: #009100">"UserID"</span>, nullable = <span class="code-keyword" style="color: #000091">false</span>)),
@AttributeOverride(name = <span class="code-quote" style="color: #009100">"groupId"</span>, column = @Column(name = <span class="code-quote" style="color: #009100">"GroupID"</span>, nullable = <span class="code-keyword" style="color: #000091">false</span>)) })
<span class="code-keyword" style="color: #000091">public</span> UserGroup getId() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.id;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = <span class="code-quote" style="color: #009100">"UserID"</span>, nullable = <span class="code-keyword" style="color: #000091">false</span>, insertable = <span class="code-keyword" style="color: #000091">false</span>, updatable = <span class="code-keyword" style="color: #000091">false</span>)
<span class="code-keyword" style="color: #000091">public</span> User getUser() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.user;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = <span class="code-quote" style="color: #009100">"GroupID"</span>, nullable = <span class="code-keyword" style="color: #000091">false</span>, insertable = <span class="code-keyword" style="color: #000091">false</span>, updatable = <span class="code-keyword" style="color: #000091">false</span>)
<span class="code-keyword" style="color: #000091">public</span> Group getGroup() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.group;
}
/* snipped the boring getters <span class="code-keyword" style="color: #000091">for</span> brevity */
/* snipped setters <span class="code-keyword" style="color: #000091">for</span> brevity */
}
</pre>
</div>
</div>
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">UserGroupId</p>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">
@Embeddable
<span class="code-keyword" style="color: #000091">public</span> class UserGroupdId <span class="code-keyword" style="color: #000091">implements</span> Serializable {
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">Integer</span> UserId;
<span class="code-keyword" style="color: #000091">private</span> <span class="code-object" style="color: #910091">Integer</span> GroupId;
/* snipped constructorss <span class="code-keyword" style="color: #000091">for</span> brevity */
@Column(name=<span class="code-quote" style="color: #009100">"UserID"</span>, nullable=<span class="code-keyword" style="color: #000091">false</span>)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">Integer</span> getUserId() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.userId;
}
        @Column(name=<span class="code-quote" style="color: #009100">"GroupID"</span>, nullable=<span class="code-keyword" style="color: #000091">false</span>)
<span class="code-keyword" style="color: #000091">public</span> <span class="code-object" style="color: #910091">Integer</span> getGroupId() {
<span class="code-keyword" style="color: #000091">return</span> <span class="code-keyword" style="color: #000091">this</span>.groupId;
}
/* snipped setters <span class="code-keyword" style="color: #000091">for</span> brevity */
/* snipped equals/hash code <span class="code-keyword" style="color: #000091">for</span> brevity */
}
</pre>
</div>
</div>
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">Intended usage</p>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">
<span class="code-comment" style="color: #808080">//repositories are crud repositories from Spring-data-jpa
</span>User u = userRepository.findOne(1);
Group g = groupRepository.findOne(1);
u.getGroups().add(g);
userRepository.save(u);
</pre>
</div>
</div>
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">I am seeing these sql statments:</p>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">
update
people
set
CreatedAt=?,
CreatedBy=?,
                Password=?,
TouchedAt=?,
TouchedBy=?,
                Username=?
where
UserID=?
insert
into
                UserGroup
(UserId, GroupId)
values
(?, ?)
</pre>
</div>
</div>
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">And this results on the null constraint violation</p>
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">I'd expect this:</p>
<div class="code panel" style="border-width: 1px;; border: 1px solid #ccc; background: #f5f5f5; font-size: 12px; line-height: 1.333; font-family: monospace; border: 1px solid #ccc; -moz-border-radius: 3px 3px 3px 3px; border-radius: 3px 3px 3px 3px; margin: 9px 0">
<div class="codeContent panelContent" style="padding: 9px 12px">
<pre class="code-java" style="margin: 10px 0 0 0; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal">
update
people
set
CreatedAt=?,
CreatedBy=?,
                Password=?,
TouchedAt=?,
TouchedBy=?,
                Username=?
where
UserID=?
insert
into
                UserGroup
(CreatedBy, CreatedAt, TouchedBy, TouchedAt, UserId, GroupId)
values
(?, ?, ?, ?, ?, ?)
</pre>
</div>
</div>
<p style="margin-top:0;margin-bottom:10px;; margin: 10px 0 0 0">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</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="email-content-main mobile-expand " style="padding: 0px; border-collapse: collapse; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #fff">
<table id="actions-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px">
<tr>
<td id="actions-pattern-container" valign="middle" style="padding: 0px; border-collapse: collapse; padding: 10px 0 10px 24px; vertical-align: middle; padding-left: 0">
<table align="left" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tr>
<td class="actions-pattern-action-icon-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 0px; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HHH-9429#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none"> <img class="actions-pattern-action-icon-image" src="cid:jira-generated-image-static-comment-icon-233a0df3-d8b8-43c0-a3f6-a54eddb0380f" alt="Add Comment" title="Add Comment" height="16" width="16" border="0" style="vertical-align: middle" /> </a>
</td>
<td class="actions-pattern-action-text-container" style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; padding-left: 5px"> <a href="https://hibernate.atlassian.net/browse/HHH-9429#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none">Add Comment</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<!-- there needs to be content in the cell for it to render in some clients -->
<tr>
<td class="email-content-rounded-bottom mobile-expand" style="padding: 0px; border-collapse: collapse; color: #fff; padding: 0 15px 0 16px; height: 5px; line-height: 5px; background-color: #fff; border-top: 0; border-left: 1px solid #ccc; border-bottom: 1px solid #ccc; border-right: 1px solid #ccc; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; mso-line-height-rule: exactly">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td id="footer-pattern" style="padding: 0px; border-collapse: collapse; padding: 12px 20px">
<table id="footer-pattern-container" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tr>
<td id="footer-pattern-text" class="mobile-resize-text" width="100%" style="padding: 0px; border-collapse: collapse; color: #999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px">
This message was sent by Atlassian JIRA <span id="footer-build-information">(v6.4-OD-05-009#64003-<span title="e99cc6b9007a6cdb8fbf4f57d1a3717d5f37f521" data-commit-id="e99cc6b9007a6cdb8fbf4f57d1a3717d5f37f521}">sha1:e99cc6b</span>)</span>
</td>
<td id="footer-pattern-logo-desktop-container" valign="top" style="padding: 0px; border-collapse: collapse; padding-left: 20px; vertical-align: top">
<table style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tr>
<td id="footer-pattern-logo-desktop-padding" style="padding: 0px; border-collapse: collapse; padding-top: 3px"> <img id="footer-pattern-logo-desktop" src="cid:jira-generated-image-static-footer-desktop-logo-c81b26d5-99fe-4090-94a6-7336bc37ef47" alt="Atlassian logo" title="Atlassian logo" width="169" height="36" class="image_fix" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>