Skip to content

Commit 8e1dbbc

Browse files
committed
HHH-19220 Add test for issue
1 parent 302d690 commit 8e1dbbc

File tree

1 file changed

+104
-0
lines changed
  • hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/lazy

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.envers.integration.lazy;
6+
7+
import org.hibernate.annotations.LazyGroup;
8+
import org.hibernate.envers.Audited;
9+
10+
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
11+
import org.hibernate.testing.orm.junit.DomainModel;
12+
import org.hibernate.testing.orm.junit.JiraKey;
13+
import org.hibernate.testing.orm.junit.SessionFactory;
14+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
15+
import org.junit.jupiter.api.BeforeEach;
16+
import org.junit.jupiter.api.Test;
17+
18+
import jakarta.persistence.Basic;
19+
import jakarta.persistence.Entity;
20+
import jakarta.persistence.FetchType;
21+
import jakarta.persistence.Id;
22+
23+
@JiraKey("")
24+
@BytecodeEnhanced
25+
@DomainModel(
26+
annotatedClasses = {
27+
LazyFieldsTest.TestEntity.class,
28+
}
29+
)
30+
@SessionFactory
31+
public class LazyFieldsTest {
32+
33+
private static final Long ID = 1L;
34+
35+
@BeforeEach
36+
public void setUp(SessionFactoryScope scope) {
37+
scope.inTransaction(
38+
session -> {
39+
TestEntity testEntity = new TestEntity( ID, "test data", "lazyString", "group A" );
40+
session.persist( testEntity );
41+
}
42+
);
43+
}
44+
45+
@Test
46+
public void testUpdate(SessionFactoryScope scope) {
47+
scope.inTransaction(
48+
session -> {
49+
TestEntity testEntity = session.find( TestEntity.class, ID );
50+
testEntity.setData( "modified test data" );
51+
}
52+
);
53+
}
54+
55+
@Entity(name = "TestEntity")
56+
public static class TestEntity {
57+
@Id
58+
private Long id;
59+
60+
@Audited
61+
@Basic(optional = false)
62+
private String data;
63+
64+
@Audited
65+
@Basic(fetch = FetchType.LAZY)
66+
private String lazyString;
67+
68+
@Audited
69+
@Basic(fetch = FetchType.LAZY)
70+
@LazyGroup("a")
71+
private String lazyStringGroupA;
72+
73+
public TestEntity() {
74+
}
75+
76+
public TestEntity(Long id, String data, String lazyString, String anotherLazyString) {
77+
this.id = id;
78+
this.data = data;
79+
this.lazyString = lazyString;
80+
this.lazyStringGroupA = anotherLazyString;
81+
}
82+
83+
public Long getId() {
84+
return id;
85+
}
86+
87+
public String getData() {
88+
return data;
89+
}
90+
91+
public void setData(String data) {
92+
this.data = data;
93+
}
94+
95+
public String getLazyString() {
96+
return lazyString;
97+
}
98+
99+
public String getLazyStringGroupA() {
100+
return lazyStringGroupA;
101+
}
102+
}
103+
104+
}

0 commit comments

Comments
 (0)