Skip to content

HHH-19457 : reproducer in 5.x vs 6.x #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.bugs.entities.EntityChildTwoSameTable;
import org.hibernate.bugs.entities.EntityParent;
import org.hibernate.bugs.entities.EntityChildOne;
import org.hibernate.bugs.entities.EntityRelation;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Assert;
import org.junit.Test;

/**
Expand All @@ -37,17 +42,21 @@ public class ORMUnitTestCase extends BaseCoreFunctionalTestCase {
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
// Foo.class,
// Bar.class
EntityChildTwoSameTable.class,
EntityParent.class,
EntityChildOne.class,
EntityRelation.class
// Foo.class,
// Bar.class
};
}

// If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
@Override
protected String[] getMappings() {
return new String[] {
// "Foo.hbm.xml",
// "Bar.hbm.xml"
// "Foo.hbm.xml",
// "Bar.hbm.xml"
};
}
// If those mappings reside somewhere other than resources/org/hibernate/test, change this.
Expand All @@ -68,12 +77,35 @@ protected void configure(Configuration configuration) {

// Add your tests, using standard JUnit.
@Test
public void hhh123Test() throws Exception {
public void hhh19457Test() throws Exception {
// BaseCoreFunctionalTestCase automatically creates the SessionFactory and provides the Session.
Session s = openSession();
Transaction tx = s.beginTransaction();

EntityRelation entityRelation = new EntityRelation();
entityRelation.setId("idRelation1");
s.save(entityRelation);

EntityChildOne entityChildOne = new EntityChildOne();
entityChildOne.setId("idChild1");
entityChildOne.setName("nameChild1");
entityChildOne.setIdRelation("idRelation1");
s.save(entityChildOne);

EntityChildTwoSameTable entityChildTwo = new EntityChildTwoSameTable();
entityChildTwo.setId("idChild2");
entityChildTwo.setChildTwoName("nameChild2");
entityChildTwo.setIdRelation("idRelation1");
s.save(entityChildTwo);
// Do stuff...
tx.commit();
s.close();

s = openSession();
tx = s.beginTransaction();
EntityRelation relation = s.get(EntityRelation.class, "idRelation1");
Assert.assertEquals("must have 2 parents", 2, relation.getParents().size());
tx.commit();
s.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.hibernate.bugs.entities;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "CHILD")
@DiscriminatorValue("15")
public class EntityChildOne extends EntityParent {

@Column(name = "name")
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.hibernate.bugs.entities;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "CHILD")
@DiscriminatorValue("24")
public class EntityChildTwoSameTable extends EntityParent {

@Column(name = "child_two_name")
private String childTwoName;

public String getChildTwoName() {
return childTwoName;
}

public void setChildTwoName(String childTwoName) {
this.childTwoName = childTwoName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

package org.hibernate.bugs.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity(name = "PARENT")
@Table(name = "PARENT")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "DISCRIMINATOR")
public abstract class EntityParent implements Serializable {

@Id
@Column(name = "id")
private String id;

@Column(name = "id_relation")
private String idRelation;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_relation", referencedColumnName = "id", insertable = false, updatable = false)
private EntityRelation relation;

public EntityRelation getRelation() {
return relation;
}

public void setRelation(EntityRelation requisition) {
this.relation = requisition;
}

public String getIdRelation() {
return idRelation;
}

public void setIdRelation(String idRelation) {
this.idRelation = idRelation;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

package org.hibernate.bugs.entities;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity(name = "RELATION")
@Table(name = "RELATION")
public class EntityRelation {
@Id
@Column(name = "id")
private String id;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "relation")
private List<EntityParent> parents;

public void setId(String id) {
this.id = id;
}

public String getId() {
return id;
}

public List<EntityParent> getParents() {
return parents;
}

public void setParents(List<EntityParent> demandes) {
this.parents = demandes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
*/
package org.hibernate.bugs;

import org.hibernate.bugs.entities.EntityChildOne;
import org.hibernate.bugs.entities.EntityChildTwoSameTable;
import org.hibernate.bugs.entities.EntityParent;
import org.hibernate.bugs.entities.EntityRelation;
import org.hibernate.cfg.AvailableSettings;

import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.Assert;
import org.junit.jupiter.api.Test;

/**
Expand All @@ -34,37 +39,61 @@
* submit it as a PR!
*/
@DomainModel(
annotatedClasses = {
// Add your entities here.
// Foo.class,
// Bar.class
},
// If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
xmlMappings = {
// "org/hibernate/test/Foo.hbm.xml",
// "org/hibernate/test/Bar.hbm.xml"
}
annotatedClasses = {
// Add your entities here.
EntityChildTwoSameTable.class,
EntityParent.class,
EntityChildOne.class,
EntityRelation.class
// Bar.class
},
// If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
xmlMappings = {
// "org/hibernate/test/Foo.hbm.xml",
// "org/hibernate/test/Bar.hbm.xml"
}
)
@ServiceRegistry(
// Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
settings = {
// For your own convenience to see generated queries:
@Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
@Setting(name = AvailableSettings.FORMAT_SQL, value = "true"),
// @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
// Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
settings = {
// For your own convenience to see generated queries:
@Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
@Setting(name = AvailableSettings.FORMAT_SQL, value = "true"),
// @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),

// Add your own settings that are a part of your quarkus configuration:
// @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ),
}
// Add your own settings that are a part of your quarkus configuration:
// @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ),
}
)
@SessionFactory
class ORMUnitTestCase {

// Add your tests, using standard JUnit 5.
@Test
void hhh123Test(SessionFactoryScope scope) throws Exception {
scope.inTransaction( session -> {
void hhh19457Test(SessionFactoryScope scope) throws Exception {
scope.inTransaction( s -> {
// Do stuff...
EntityRelation entityRelation = new EntityRelation();
entityRelation.setId("idRelation1");
s.save(entityRelation);

EntityChildOne entityChildOne = new EntityChildOne();
entityChildOne.setId("idChild1");
entityChildOne.setName("nameChild1");
entityChildOne.setIdRelation("idRelation1");
s.save(entityChildOne);

EntityChildTwoSameTable entityChildTwo = new EntityChildTwoSameTable();
entityChildTwo.setId("idChild2");
entityChildTwo.setChildTwoName("nameChild2");
entityChildTwo.setIdRelation("idRelation1");
s.save(entityChildTwo);
} );

scope.inSession(s -> {
EntityRelation relation = s.get(EntityRelation.class, "idRelation1");
// If you disable the -ea flag, the assertion will fail.
Assert.assertEquals("must have 2 parents", 2, relation.getParents().size());
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

package org.hibernate.bugs.entities;

import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;

@Entity
@Table(name = "CHILD")
@DiscriminatorValue("15")
public class EntityChildOne extends EntityParent {

@Column(name = "name")
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

package org.hibernate.bugs.entities;

import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;

@Entity
@Table(name = "CHILD")
@DiscriminatorValue("24")
public class EntityChildTwoSameTable extends EntityParent {

@Column(name = "child_two_name")
private String childTwoName;

public String getChildTwoName() {
return childTwoName;
}

public void setChildTwoName(String childTwoName) {
this.childTwoName = childTwoName;
}
}
Loading