Skip to content

Commit ea00d69

Browse files
committed
HHH-19897 Add test for issue
1 parent 815ada8 commit ea00d69

File tree

3 files changed

+197
-0
lines changed

3 files changed

+197
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.manytomany;
6+
7+
import java.util.List;
8+
9+
import org.hibernate.cfg.Configuration;
10+
import org.hibernate.envers.Audited;
11+
import org.hibernate.envers.NotAudited;
12+
import org.hibernate.envers.boot.EnversMappingException;
13+
14+
import org.hibernate.testing.orm.junit.Jira;
15+
import org.hibernate.testing.util.ServiceRegistryUtil;
16+
import org.junit.Test;
17+
18+
import jakarta.persistence.Entity;
19+
import jakarta.persistence.Id;
20+
import jakarta.persistence.ManyToMany;
21+
import jakarta.persistence.OneToMany;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
import static org.junit.Assert.assertThrows;
25+
26+
@Jira("https://hibernate.atlassian.net/browse/HHH-19897")
27+
public class MappedByNotAuditedToManyTest {
28+
@Test
29+
public void testMappingException() {
30+
final Configuration cfg = new Configuration().addAnnotatedClasses( ToManyParent.class, ToManyChild.class );
31+
ServiceRegistryUtil.applySettings( cfg.getStandardServiceRegistryBuilder() );
32+
final var enversMappingException = assertThrows(
33+
"Expecting EnversMappingException to be thrown due to @NotAudited on owning side of bidirectional association",
34+
EnversMappingException.class,
35+
cfg::buildSessionFactory
36+
);
37+
assertThat( enversMappingException ).hasMessageContainingAll(
38+
"Could not resolve mapped by property for association",
39+
"parents"
40+
);
41+
}
42+
43+
@Entity(name = "ToOneEntity")
44+
@Audited
45+
static class ToManyParent {
46+
@Id
47+
private Long id;
48+
49+
private String parentData;
50+
51+
@ManyToMany
52+
@NotAudited
53+
private List<ToManyChild> children;
54+
}
55+
56+
@Entity(name = "ToOneChild")
57+
@Audited
58+
static class ToManyChild {
59+
@Id
60+
private Long id;
61+
62+
private String childData;
63+
64+
@OneToMany(mappedBy = "children")
65+
private List<ToManyParent> parents;
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.manytoone.bidirectional;
6+
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.ManyToOne;
10+
import jakarta.persistence.OneToMany;
11+
import org.hibernate.cfg.Configuration;
12+
import org.hibernate.envers.Audited;
13+
import org.hibernate.envers.NotAudited;
14+
import org.hibernate.envers.boot.EnversMappingException;
15+
16+
import org.hibernate.testing.orm.junit.Jira;
17+
import org.hibernate.testing.util.ServiceRegistryUtil;
18+
import org.junit.Test;
19+
20+
import java.util.List;
21+
22+
import static org.assertj.core.api.Assertions.assertThat;
23+
import static org.junit.Assert.assertThrows;
24+
25+
@Jira("https://hibernate.atlassian.net/browse/HHH-19897")
26+
public class MappedByNotAuditedManyToOneTest {
27+
@Test
28+
public void testMappingException() {
29+
final Configuration cfg = new Configuration().addAnnotatedClasses( ToOneParent.class, ToOneChild.class );
30+
ServiceRegistryUtil.applySettings( cfg.getStandardServiceRegistryBuilder() );
31+
final var enversMappingException = assertThrows(
32+
"Expecting EnversMappingException to be thrown due to @NotAudited on owning side of bidirectional association",
33+
EnversMappingException.class,
34+
cfg::buildSessionFactory
35+
);
36+
assertThat( enversMappingException ).hasMessageContainingAll(
37+
"Could not resolve mapped by property for association",
38+
"parents"
39+
);
40+
}
41+
42+
@Entity(name = "ToOneEntity")
43+
@Audited
44+
static class ToOneParent {
45+
@Id
46+
private Long id;
47+
48+
private String parentData;
49+
50+
@ManyToOne
51+
@NotAudited
52+
private ToOneChild child;
53+
}
54+
55+
@Entity(name = "ToOneChild")
56+
@Audited
57+
static class ToOneChild {
58+
@Id
59+
private Long id;
60+
61+
private String childData;
62+
63+
@OneToMany(mappedBy = "child")
64+
private List<ToOneParent> parents;
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.onetoone.bidirectional;
6+
7+
import org.hibernate.cfg.Configuration;
8+
import org.hibernate.envers.Audited;
9+
import org.hibernate.envers.NotAudited;
10+
import org.hibernate.envers.boot.EnversMappingException;
11+
12+
import org.hibernate.testing.orm.junit.Jira;
13+
import org.hibernate.testing.util.ServiceRegistryUtil;
14+
import org.junit.Test;
15+
16+
import jakarta.persistence.Entity;
17+
import jakarta.persistence.Id;
18+
import jakarta.persistence.OneToOne;
19+
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.junit.Assert.assertThrows;
22+
23+
@Jira("https://hibernate.atlassian.net/browse/HHH-19897")
24+
public class MappedByNotAuditedOneToOneTest {
25+
@Test
26+
public void testMappingException() {
27+
final Configuration cfg = new Configuration().addAnnotatedClasses( ToOneParent.class, ToOneChild.class );
28+
ServiceRegistryUtil.applySettings( cfg.getStandardServiceRegistryBuilder() );
29+
final var enversMappingException = assertThrows(
30+
"Expecting EnversMappingException to be thrown due to @NotAudited on owning side of bidirectional association",
31+
EnversMappingException.class,
32+
cfg::buildSessionFactory
33+
);
34+
assertThat( enversMappingException ).hasMessageContainingAll(
35+
"Could not resolve mapped by property [child] for association",
36+
"parent"
37+
);
38+
}
39+
40+
@Entity(name = "ToOneEntity")
41+
@Audited
42+
static class ToOneParent {
43+
@Id
44+
private Long id;
45+
46+
private String parentData;
47+
48+
@OneToOne
49+
@NotAudited
50+
private ToOneChild child;
51+
}
52+
53+
@Entity(name = "ToOneChild")
54+
@Audited
55+
static class ToOneChild {
56+
@Id
57+
private Long id;
58+
59+
private String childData;
60+
61+
@OneToOne(mappedBy = "child")
62+
private ToOneParent parent;
63+
}
64+
}

0 commit comments

Comments
 (0)