Skip to content

Commit 540c9f8

Browse files
dreab8beikov
authored andcommitted
HHH-16126 Add test for issue
1 parent 3cae865 commit 540c9f8

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package org.hibernate.orm.test.caching;
2+
3+
import java.util.HashSet;
4+
import java.util.List;
5+
import java.util.Set;
6+
7+
import org.hibernate.annotations.Cache;
8+
import org.hibernate.annotations.CacheConcurrencyStrategy;
9+
10+
import org.hibernate.testing.TestForIssue;
11+
import org.hibernate.testing.orm.junit.DomainModel;
12+
import org.hibernate.testing.orm.junit.SessionFactory;
13+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
14+
import org.junit.jupiter.api.BeforeAll;
15+
import org.junit.jupiter.api.Test;
16+
17+
import jakarta.persistence.Cacheable;
18+
import jakarta.persistence.Entity;
19+
import jakarta.persistence.GeneratedValue;
20+
import jakarta.persistence.Id;
21+
import jakarta.persistence.ManyToOne;
22+
import jakarta.persistence.OneToMany;
23+
import jakarta.persistence.Table;
24+
import jakarta.persistence.Version;
25+
26+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
27+
28+
@DomainModel(
29+
annotatedClasses = {
30+
CachingAndVersionTest.Domain.class,
31+
CachingAndVersionTest.Server.class
32+
}
33+
)
34+
@SessionFactory
35+
@TestForIssue(jiraKey = "HHH-16126")
36+
public class CachingAndVersionTest {
37+
38+
@BeforeAll
39+
public void setUp(SessionFactoryScope scope) {
40+
scope.inTransaction(
41+
session -> {
42+
Domain domain = new Domain();
43+
Server server = new Server();
44+
domain.addServer( server );
45+
46+
session.persist( domain );
47+
session.persist( server );
48+
}
49+
);
50+
}
51+
52+
@Test
53+
public void testSelect(SessionFactoryScope scope) {
54+
scope.inTransaction(
55+
session -> {
56+
List<Domain> domains =
57+
session.createQuery(
58+
"SELECT DISTINCT d FROM Domain d LEFT JOIN FETCH d.servers s",
59+
Domain.class
60+
)
61+
.getResultList();
62+
assertThat( domains.size() ).isEqualTo( 1 );
63+
}
64+
);
65+
}
66+
67+
@Entity(name = "Domain")
68+
@Table(name = "DOMAIN_TABLE")
69+
public static class Domain {
70+
@Id
71+
@GeneratedValue
72+
private Long id;
73+
74+
@Version
75+
private Integer rowVersion;
76+
77+
@OneToMany(mappedBy = "domain")
78+
private Set<Server> servers = new HashSet<>();
79+
80+
public Long getId() {
81+
return id;
82+
}
83+
84+
public Integer getRowVersion() {
85+
return rowVersion;
86+
}
87+
88+
public Set<Server> getServers() {
89+
return servers;
90+
}
91+
92+
public void addServer(Server server) {
93+
servers.add( server );
94+
server.setDomain( this );
95+
}
96+
}
97+
98+
@Entity(name = "Server")
99+
@Table(name = "SERVER_TABLE")
100+
@Cacheable
101+
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
102+
public static class Server {
103+
@Id
104+
@GeneratedValue
105+
private Long id;
106+
107+
@ManyToOne
108+
private Domain domain;
109+
110+
@Version
111+
private Integer rowVersion;
112+
113+
public Long getId() {
114+
return id;
115+
}
116+
117+
public Domain getDomain() {
118+
return domain;
119+
}
120+
121+
public void setDomain(Domain domain) {
122+
this.domain = domain;
123+
}
124+
125+
public Integer getRowVersion() {
126+
return rowVersion;
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)