Skip to content

Commit a104735

Browse files
author
Vincent
committed
HHH-19457 : reproducer in 5.x vs 6.x
1 parent 97ca8e8 commit a104735

File tree

10 files changed

+453
-24
lines changed

10 files changed

+453
-24
lines changed

orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/ORMUnitTestCase.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717

1818
import org.hibernate.Session;
1919
import org.hibernate.Transaction;
20+
import org.hibernate.bugs.entities.EntityChildTwoSameDiscriminator;
21+
import org.hibernate.bugs.entities.EntityParent;
22+
import org.hibernate.bugs.entities.EntityChildOne;
23+
import org.hibernate.bugs.entities.EntityRelation;
2024
import org.hibernate.cfg.AvailableSettings;
2125
import org.hibernate.cfg.Configuration;
2226
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
27+
import org.junit.Assert;
2328
import org.junit.Test;
2429

2530
/**
@@ -37,17 +42,21 @@ public class ORMUnitTestCase extends BaseCoreFunctionalTestCase {
3742
@Override
3843
protected Class[] getAnnotatedClasses() {
3944
return new Class[] {
40-
// Foo.class,
41-
// Bar.class
45+
EntityChildTwoSameDiscriminator.class,
46+
EntityParent.class,
47+
EntityChildOne.class,
48+
EntityRelation.class
49+
// Foo.class,
50+
// Bar.class
4251
};
4352
}
4453

4554
// If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
4655
@Override
4756
protected String[] getMappings() {
4857
return new String[] {
49-
// "Foo.hbm.xml",
50-
// "Bar.hbm.xml"
58+
// "Foo.hbm.xml",
59+
// "Bar.hbm.xml"
5160
};
5261
}
5362
// If those mappings reside somewhere other than resources/org/hibernate/test, change this.
@@ -72,8 +81,31 @@ public void hhh123Test() throws Exception {
7281
// BaseCoreFunctionalTestCase automatically creates the SessionFactory and provides the Session.
7382
Session s = openSession();
7483
Transaction tx = s.beginTransaction();
84+
85+
EntityRelation entityRelation = new EntityRelation();
86+
entityRelation.setId("idRelation1");
87+
s.save(entityRelation);
88+
89+
EntityChildOne entityChildOne = new EntityChildOne();
90+
entityChildOne.setId("idChild1");
91+
entityChildOne.setName("nameChild1");
92+
entityChildOne.setIdRelation("idRelation1");
93+
s.save(entityChildOne);
94+
95+
EntityChildTwoSameDiscriminator entityChildTwo = new EntityChildTwoSameDiscriminator();
96+
entityChildTwo.setId("idChild2");
97+
entityChildTwo.setChildTwoName("nameChild2");
98+
entityChildTwo.setIdRelation("idRelation1");
99+
s.save(entityChildTwo);
75100
// Do stuff...
76101
tx.commit();
77102
s.close();
103+
104+
s = openSession();
105+
tx = s.beginTransaction();
106+
EntityRelation relation = s.get(EntityRelation.class, "idRelation1");
107+
Assert.assertEquals("must have 2 parents", 2, relation.getParents().size());
108+
tx.commit();
109+
s.close();
78110
}
79111
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//***********************************************************************************
2+
//
3+
// (C) Copyright Bouygues Telecom 2025.
4+
//
5+
// Utilisation, reproduction et divulgation interdites
6+
// sans autorisation ecrite de Bouygues Telecom.
7+
//
8+
// Createur : VIMEUNIE
9+
// Date creation : 07 mai 2025
10+
//
11+
//***********************************************************************************
12+
package org.hibernate.bugs.entities;
13+
14+
import javax.persistence.Column;
15+
import javax.persistence.DiscriminatorValue;
16+
import javax.persistence.Entity;
17+
import javax.persistence.Table;
18+
19+
@Entity
20+
@Table(name = "CHILD")
21+
@DiscriminatorValue("15")
22+
public class EntityChildOne extends EntityParent {
23+
24+
@Column(name = "name")
25+
private String name;
26+
27+
public String getName() {
28+
return name;
29+
}
30+
31+
public void setName(String name) {
32+
this.name = name;
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//***********************************************************************************
2+
//
3+
// (C) Copyright Bouygues Telecom 2025.
4+
//
5+
// Utilisation, reproduction et divulgation interdites
6+
// sans autorisation ecrite de Bouygues Telecom.
7+
//
8+
// Createur : VIMEUNIE
9+
// Date creation : 07 mai 2025
10+
//
11+
//***********************************************************************************
12+
package org.hibernate.bugs.entities;
13+
14+
import javax.persistence.Column;
15+
import javax.persistence.DiscriminatorValue;
16+
import javax.persistence.Entity;
17+
import javax.persistence.Table;
18+
19+
@Entity
20+
@Table(name = "CHILD")
21+
@DiscriminatorValue("24")
22+
public class EntityChildTwoSameDiscriminator extends EntityParent {
23+
24+
@Column(name = "child_two_name")
25+
private String childTwoName;
26+
27+
public String getChildTwoName() {
28+
return childTwoName;
29+
}
30+
31+
public void setChildTwoName(String childTwoName) {
32+
this.childTwoName = childTwoName;
33+
}
34+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//***********************************************************************************
2+
//
3+
// (C) Copyright Bouygues Telecom 2025.
4+
//
5+
// Utilisation, reproduction et divulgation interdites
6+
// sans autorisation ecrite de Bouygues Telecom.
7+
//
8+
// Createur : VIMEUNIE
9+
// Date creation : 07 mai 2025
10+
//
11+
//***********************************************************************************
12+
package org.hibernate.bugs.entities;
13+
14+
import java.io.Serializable;
15+
16+
import javax.persistence.Column;
17+
import javax.persistence.DiscriminatorColumn;
18+
import javax.persistence.DiscriminatorType;
19+
import javax.persistence.Entity;
20+
import javax.persistence.FetchType;
21+
import javax.persistence.Id;
22+
import javax.persistence.Inheritance;
23+
import javax.persistence.InheritanceType;
24+
import javax.persistence.JoinColumn;
25+
import javax.persistence.ManyToOne;
26+
import javax.persistence.Table;
27+
28+
@Entity(name = "PARENT")
29+
@Table(name = "PARENT")
30+
@Inheritance(strategy = InheritanceType.JOINED)
31+
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "CODTYPDEM")
32+
public abstract class EntityParent implements Serializable {
33+
34+
@Id
35+
@Column(name = "id")
36+
private String id;
37+
38+
@Column(name = "id_relation")
39+
private String idRelation;
40+
41+
@ManyToOne(fetch = FetchType.LAZY)
42+
@JoinColumn(name = "id_relation", referencedColumnName = "id", insertable = false, updatable = false)
43+
private EntityRelation relation;
44+
45+
public EntityRelation getRelation() {
46+
return relation;
47+
}
48+
49+
public void setRelation(EntityRelation requisition) {
50+
this.relation = requisition;
51+
}
52+
53+
public String getIdRelation() {
54+
return idRelation;
55+
}
56+
57+
public void setIdRelation(String idRelation) {
58+
this.idRelation = idRelation;
59+
}
60+
61+
public String getId() {
62+
return id;
63+
}
64+
65+
public void setId(String id) {
66+
this.id = id;
67+
}
68+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//***********************************************************************************
2+
//
3+
// (C) Copyright Bouygues Telecom 2025.
4+
//
5+
// Utilisation, reproduction et divulgation interdites
6+
// sans autorisation ecrite de Bouygues Telecom.
7+
//
8+
// Createur : VIMEUNIE
9+
// Date creation : 07 mai 2025
10+
//
11+
//***********************************************************************************
12+
package org.hibernate.bugs.entities;
13+
14+
import java.util.List;
15+
16+
import javax.persistence.Column;
17+
import javax.persistence.Entity;
18+
import javax.persistence.FetchType;
19+
import javax.persistence.Id;
20+
import javax.persistence.OneToMany;
21+
import javax.persistence.Table;
22+
23+
@Entity(name = "RELATION")
24+
@Table(name = "RELATION")
25+
public class EntityRelation {
26+
@Id
27+
@Column(name = "id")
28+
private String id;
29+
30+
@OneToMany(fetch = FetchType.LAZY, mappedBy = "relation")
31+
private List<EntityParent> parents;
32+
33+
public void setId(String id) {
34+
this.id = id;
35+
}
36+
37+
public String getId() {
38+
return id;
39+
}
40+
41+
public List<EntityParent> getParents() {
42+
return parents;
43+
}
44+
45+
public void setParents(List<EntityParent> demandes) {
46+
this.parents = demandes;
47+
}
48+
}

orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/ORMUnitTestCase.java

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@
1515
*/
1616
package org.hibernate.bugs;
1717

18+
import org.hibernate.bugs.entities.EntityChildOne;
19+
import org.hibernate.bugs.entities.EntityChildTwoSameDiscriminator;
20+
import org.hibernate.bugs.entities.EntityParent;
21+
import org.hibernate.bugs.entities.EntityRelation;
1822
import org.hibernate.cfg.AvailableSettings;
1923

2024
import org.hibernate.testing.orm.junit.DomainModel;
2125
import org.hibernate.testing.orm.junit.ServiceRegistry;
2226
import org.hibernate.testing.orm.junit.SessionFactory;
2327
import org.hibernate.testing.orm.junit.SessionFactoryScope;
2428
import org.hibernate.testing.orm.junit.Setting;
29+
import org.junit.Assert;
2530
import org.junit.jupiter.api.Test;
2631

2732
/**
@@ -34,37 +39,61 @@
3439
* submit it as a PR!
3540
*/
3641
@DomainModel(
37-
annotatedClasses = {
38-
// Add your entities here.
39-
// Foo.class,
40-
// Bar.class
41-
},
42-
// If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
43-
xmlMappings = {
44-
// "org/hibernate/test/Foo.hbm.xml",
45-
// "org/hibernate/test/Bar.hbm.xml"
46-
}
42+
annotatedClasses = {
43+
// Add your entities here.
44+
EntityChildTwoSameDiscriminator.class,
45+
EntityParent.class,
46+
EntityChildOne.class,
47+
EntityRelation.class
48+
// Bar.class
49+
},
50+
// If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
51+
xmlMappings = {
52+
// "org/hibernate/test/Foo.hbm.xml",
53+
// "org/hibernate/test/Bar.hbm.xml"
54+
}
4755
)
4856
@ServiceRegistry(
49-
// Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
50-
settings = {
51-
// For your own convenience to see generated queries:
52-
@Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
53-
@Setting(name = AvailableSettings.FORMAT_SQL, value = "true"),
54-
// @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
57+
// Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
58+
settings = {
59+
// For your own convenience to see generated queries:
60+
@Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
61+
@Setting(name = AvailableSettings.FORMAT_SQL, value = "true"),
62+
// @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
5563

56-
// Add your own settings that are a part of your quarkus configuration:
57-
// @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ),
58-
}
64+
// Add your own settings that are a part of your quarkus configuration:
65+
// @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ),
66+
}
5967
)
6068
@SessionFactory
6169
class ORMUnitTestCase {
6270

6371
// Add your tests, using standard JUnit 5.
6472
@Test
6573
void hhh123Test(SessionFactoryScope scope) throws Exception {
66-
scope.inTransaction( session -> {
74+
scope.inTransaction( s -> {
6775
// Do stuff...
76+
EntityRelation entityRelation = new EntityRelation();
77+
entityRelation.setId("idRelation1");
78+
s.save(entityRelation);
79+
80+
EntityChildOne entityChildOne = new EntityChildOne();
81+
entityChildOne.setId("idChild1");
82+
entityChildOne.setName("nameChild1");
83+
entityChildOne.setIdRelation("idRelation1");
84+
s.save(entityChildOne);
85+
86+
EntityChildTwoSameDiscriminator entityChildTwo = new EntityChildTwoSameDiscriminator();
87+
entityChildTwo.setId("idChild2");
88+
entityChildTwo.setChildTwoName("nameChild2");
89+
entityChildTwo.setIdRelation("idRelation1");
90+
s.save(entityChildTwo);
6891
} );
92+
93+
scope.inSession(s -> {
94+
EntityRelation relation = s.get(EntityRelation.class, "idRelation1");
95+
// If you disable the -ea flag, the assertion will fail.
96+
Assert.assertEquals("must have 2 parents", 2, relation.getParents().size());
97+
});
6998
}
7099
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//***********************************************************************************
2+
//
3+
// (C) Copyright Bouygues Telecom 2025.
4+
//
5+
// Utilisation, reproduction et divulgation interdites
6+
// sans autorisation ecrite de Bouygues Telecom.
7+
//
8+
// Createur : VIMEUNIE
9+
// Date creation : 07 mai 2025
10+
//
11+
//***********************************************************************************
12+
package org.hibernate.bugs.entities;
13+
14+
import jakarta.persistence.Column;
15+
import jakarta.persistence.DiscriminatorValue;
16+
import jakarta.persistence.Entity;
17+
import jakarta.persistence.Table;
18+
19+
@Entity
20+
@Table(name = "CHILD")
21+
@DiscriminatorValue("15")
22+
public class EntityChildOne extends EntityParent {
23+
24+
@Column(name = "name")
25+
private String name;
26+
27+
public String getName() {
28+
return name;
29+
}
30+
31+
public void setName(String name) {
32+
this.name = name;
33+
}
34+
}

0 commit comments

Comments
 (0)