Skip to content

Commit 90bf4f4

Browse files
mira-silhavydreab8
authored andcommitted
HHH-19387 - Reformat and reword test entities
1 parent e5c2197 commit 90bf4f4

File tree

2 files changed

+40
-44
lines changed

2 files changed

+40
-44
lines changed

hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityInitializerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,8 +1634,8 @@ public void resolveState(EntityInitializerData data) {
16341634
castNonNull( discriminatorAssembler ),
16351635
entityDescriptor
16361636
);
1637-
if (data.concreteDescriptor == null) {
1638-
// Return because the value is null
1637+
if ( data.concreteDescriptor == null ) {
1638+
// this should imply the entity is missing
16391639
return;
16401640
}
16411641
}

hibernate-core/src/test/java/org/hibernate/orm/test/querycache/EntityWithCollectionReloadCacheInheritanceTest.java

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,6 @@
44
*/
55
package org.hibernate.orm.test.querycache;
66

7-
import java.util.Arrays;
8-
import java.util.List;
9-
import java.util.Set;
10-
11-
import org.hibernate.annotations.JdbcTypeCode;
12-
import org.hibernate.type.SqlTypes;
13-
14-
import org.hibernate.testing.orm.junit.DomainModel;
15-
import org.hibernate.testing.orm.junit.Jira;
16-
import org.hibernate.testing.orm.junit.SessionFactory;
17-
import org.hibernate.testing.orm.junit.SessionFactoryScope;
18-
import org.junit.jupiter.api.AfterAll;
19-
import org.junit.jupiter.api.BeforeAll;
20-
import org.junit.jupiter.api.Test;
21-
22-
import jakarta.persistence.Access;
237
import jakarta.persistence.Column;
248
import jakarta.persistence.DiscriminatorColumn;
259
import jakarta.persistence.DiscriminatorValue;
@@ -28,20 +12,34 @@
2812
import jakarta.persistence.FetchType;
2913
import jakarta.persistence.GeneratedValue;
3014
import jakarta.persistence.Id;
15+
import jakarta.persistence.Inheritance;
16+
import jakarta.persistence.InheritanceType;
3117
import jakarta.persistence.JoinColumn;
3218
import jakarta.persistence.JoinTable;
3319
import jakarta.persistence.ManyToMany;
20+
import org.hibernate.annotations.JdbcTypeCode;
21+
import org.hibernate.testing.orm.junit.DomainModel;
22+
import org.hibernate.testing.orm.junit.Jira;
23+
import org.hibernate.testing.orm.junit.SessionFactory;
24+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
25+
import org.hibernate.type.SqlTypes;
26+
import org.junit.jupiter.api.AfterAll;
27+
import org.junit.jupiter.api.BeforeAll;
28+
import org.junit.jupiter.api.Test;
29+
30+
import java.util.Arrays;
31+
import java.util.List;
32+
import java.util.Set;
3433

35-
import static jakarta.persistence.AccessType.FIELD;
3634
import static jakarta.persistence.EnumType.STRING;
3735
import static org.assertj.core.api.Assertions.assertThat;
3836

3937
/**
40-
* @author miroslav silhavy
38+
* @author Miroslav Silhavy
4139
*/
4240
@DomainModel(annotatedClasses = {
4341
EntityWithCollectionReloadCacheInheritanceTest.HighSchoolStudent.class,
44-
EntityWithCollectionReloadCacheInheritanceTest.DefaultSubject.class,
42+
EntityWithCollectionReloadCacheInheritanceTest.Subject.class,
4543
EntityWithCollectionReloadCacheInheritanceTest.EnglishSubject.class
4644
})
4745
@SessionFactory
@@ -51,7 +49,7 @@ public class EntityWithCollectionReloadCacheInheritanceTest {
5149
@Test
5250
public void test(SessionFactoryScope scope) {
5351
scope.inTransaction( session -> {
54-
List<HighSchoolStudent> list = session.createQuery(
52+
List<HighSchoolStudent> highSchoolStudents = session.createQuery(
5553
"select s" +
5654
" from HighSchoolStudent s left join fetch s.subjects m" +
5755
" where s.name in :names", HighSchoolStudent.class
@@ -60,9 +58,9 @@ public void test(SessionFactoryScope scope) {
6058
.setCacheable( true )
6159
.list();
6260

63-
assertThat( list ).hasSize( 1 );
61+
assertThat( highSchoolStudents ).hasSize( 1 );
6462

65-
list = session.createQuery(
63+
highSchoolStudents = session.createQuery(
6664
"select s" +
6765
" from HighSchoolStudent s left join fetch s.subjects m" +
6866
" where s.name in :names", HighSchoolStudent.class
@@ -71,7 +69,7 @@ public void test(SessionFactoryScope scope) {
7169
.setCacheable( true )
7270
.list();
7371

74-
assertThat( list ).hasSize( 2 );
72+
assertThat( highSchoolStudents ).hasSize( 2 );
7573
} );
7674
}
7775

@@ -94,7 +92,6 @@ public void tearDown(SessionFactoryScope scope) {
9492
}
9593

9694
@Entity(name = "HighSchoolStudent")
97-
@Access(FIELD)
9895
static class HighSchoolStudent {
9996

10097
@Id
@@ -105,12 +102,12 @@ static class HighSchoolStudent {
105102
@Column(name = "name")
106103
private String name;
107104

108-
@ManyToMany(targetEntity = DefaultSubject.class, fetch = FetchType.LAZY)
105+
@ManyToMany(targetEntity = Subject.class, fetch = FetchType.LAZY)
109106
@JoinTable(name = "STUDENT_SUBJECT",
110107
joinColumns = { @JoinColumn(name = "student_id") },
111108
inverseJoinColumns = { @JoinColumn(name = "subject_id") }
112109
)
113-
private Set<DefaultSubject> subjects;
110+
private Set<Subject> subjects;
114111

115112
public Long getId() {
116113
return id;
@@ -128,37 +125,32 @@ public void setName(String name) {
128125
this.name = name;
129126
}
130127

131-
public Set<DefaultSubject> getSubjects() {
128+
public Set<Subject> getSubjects() {
132129
return subjects;
133130
}
134131

135-
public void setMajors(Set<DefaultSubject> subjects) {
132+
public void setSubjects(Set<Subject> subjects) {
136133
this.subjects = subjects;
137134
}
138135

139136
}
140137

141-
@Entity(name = "DefaultSubject")
138+
@Entity(name = "Subject")
139+
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
142140
@DiscriminatorValue("DEFAULT")
143141
@DiscriminatorColumn(name = "TYPE", length = 20)
144-
@Access(FIELD)
145-
static class DefaultSubject {
142+
static class Subject {
146143

147-
enum SubjectType {
148-
DEFAULT,
149-
ENGLISH
150-
}
144+
@Id
145+
@GeneratedValue
146+
@Column(name = "id")
147+
private Long id;
151148

152149
@Column(name = "TYPE", nullable = false, length = 20, insertable = false, updatable = false)
153150
@Enumerated(STRING)
154151
@JdbcTypeCode(SqlTypes.VARCHAR)
155152
private SubjectType type;
156153

157-
@Id
158-
@GeneratedValue
159-
@Column(name = "id")
160-
private Long id;
161-
162154
public Long getId() {
163155
return id;
164156
}
@@ -171,8 +163,12 @@ public void setId(Long id) {
171163

172164
@Entity(name = "EnglishSubject")
173165
@DiscriminatorValue("ENGLISH")
174-
@Access(FIELD)
175-
static class EnglishSubject extends DefaultSubject {
166+
static class EnglishSubject extends Subject {
167+
}
168+
169+
enum SubjectType {
170+
DEFAULT,
171+
ENGLISH
176172
}
177173

178174
}

0 commit comments

Comments
 (0)