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

LazyInitializationException when Envers persists audit data that uses a proxy with JPA_PROXY_COMPLIANCE enabled under JTA

Description

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 @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; } }

Environment

None

Status

Assignee

Chris Cranford

Reporter

Chris Cranford

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.3.7
5.4.0

Priority

Major