When operating in a JTA environment with {{hibernate.jpa.compliance.proxy=true}}, if an entity that is modified has a lazy-association, as shown below, Envers will result in a LazyInitializationException when attempting to resolve the association's identifier because the associated {{Session}} has since been closed. The entity mappings {code} @Entity(name = "AuthUser") @Audited public static class AuthUser { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String someValue; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="idclient", insertable=false, updatable = false) private AuthClient authClient;
public AuthUser() {
}
public AuthUser(Integer id, String someValue) { this.id = id; this.someValue = someValue; }
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
public String getSomeValue() { return someValue; }
public void setSomeValue(String someValue) { this.someValue = someValue; }
public AuthClient getAuthClient() { return authClient; }
public void setAuthClient(AuthClient authClient) { this.authClient = authClient; } }
@Entity(name = "AuthClient") @Audited public static class AuthClient { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id;
@OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "idclient") private List<AuthUser> authUsers = new ArrayList<>();
public AuthClient() {
}
public AuthClient(Integer id) { this.id = id; }
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
public List<AuthUser> getAuthUsers() { return authUsers; }
public void setAuthUsers(List<AuthUser> authUsers) { this.authUsers = authUsers; } } {code} |
|