-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HHH-16979] Change SqmPathSource resolution method call
- Loading branch information
1 parent
71cb347
commit f2b4454
Showing
7 changed files
with
192 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
.../test/java/org/hibernate/orm/test/persister/entity/JoinedInheritanceImplicitJoinTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
package org.hibernate.orm.test.persister.entity; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Inheritance; | ||
import jakarta.persistence.InheritanceType; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Tuple; | ||
import jakarta.persistence.TypedQuery; | ||
import jakarta.persistence.criteria.CriteriaBuilder; | ||
import jakarta.persistence.criteria.CriteriaQuery; | ||
import jakarta.persistence.criteria.Join; | ||
import jakarta.persistence.criteria.Root; | ||
import org.hibernate.cfg.AvailableSettings; | ||
import org.hibernate.testing.TestForIssue; | ||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; | ||
import org.hibernate.testing.orm.junit.Jpa; | ||
import org.hibernate.testing.orm.junit.Setting; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@TestForIssue(jiraKey = "HHH-16979") | ||
@Jpa(annotatedClasses = { | ||
JoinedInheritanceImplicitJoinTest.MasterEntity.class, | ||
JoinedInheritanceImplicitJoinTest.ChildEntity.class, | ||
JoinedInheritanceImplicitJoinTest.RelatedEntity.class | ||
}, properties = { | ||
@Setting(name = AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, value = "true") | ||
}) | ||
public class JoinedInheritanceImplicitJoinTest { | ||
|
||
@BeforeEach | ||
public void setup(EntityManagerFactoryScope scope) { | ||
scope.inTransaction(entityManager -> { | ||
final var childEntity = new ChildEntity(); | ||
childEntity.setMasterField("masterValue001"); | ||
childEntity.setChildField("childValue001"); | ||
|
||
RelatedEntity relatedEntity = new RelatedEntity(); | ||
relatedEntity.setRelatedField("relatedValue001"); | ||
relatedEntity.setChildEntity(childEntity); | ||
|
||
RelatedEntity relatedEntity2 = new RelatedEntity(); | ||
relatedEntity2.setRelatedField("relatedValue002"); | ||
relatedEntity2.setChildEntity(childEntity); | ||
|
||
Set<RelatedEntity> relatedEntityHashSet = Set.of(relatedEntity, relatedEntity2); | ||
|
||
childEntity.setRelatedEntitySet(relatedEntityHashSet); | ||
|
||
entityManager.persist(childEntity); | ||
entityManager.persist(relatedEntity); | ||
entityManager.persist(relatedEntity2); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testImplicitJoinWithoutRelatedEntity(EntityManagerFactoryScope scope) { | ||
scope.inTransaction(entityManager -> { | ||
CriteriaBuilder cb = entityManager.getCriteriaBuilder(); | ||
CriteriaQuery<Tuple> query = cb.createQuery(Tuple.class); | ||
Root<ChildEntity> root = query.from(ChildEntity.class); | ||
|
||
query.multiselect( | ||
root.get("masterField"), | ||
root.get("childField") | ||
); | ||
|
||
TypedQuery<Tuple> result = entityManager.createQuery(query); | ||
List<Tuple> resultList = result.getResultList(); | ||
|
||
Assertions.assertFalse(resultList.isEmpty()); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testImplicitJoinWithRelatedEntity(EntityManagerFactoryScope scope) { | ||
scope.inTransaction(entityManager -> { | ||
CriteriaBuilder cb = entityManager.getCriteriaBuilder(); | ||
CriteriaQuery<Tuple> query = cb.createQuery(Tuple.class); | ||
Root<ChildEntity> root = query.from(ChildEntity.class); | ||
Join<ChildEntity, RelatedEntity> relatedEntityJoin = root.join("relatedEntitySet"); | ||
|
||
query.multiselect( | ||
root.get("masterField"), | ||
root.get("childField"), | ||
relatedEntityJoin.get("relatedField") | ||
); | ||
|
||
TypedQuery<Tuple> result = entityManager.createQuery(query); | ||
List<Tuple> resultList = result.getResultList(); | ||
|
||
Assertions.assertFalse(resultList.isEmpty()); | ||
}); | ||
} | ||
|
||
@Entity | ||
@Inheritance(strategy = InheritanceType.JOINED) | ||
public class MasterEntity { | ||
@Id | ||
@GeneratedValue | ||
public Long id; | ||
|
||
public String masterField; | ||
|
||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getMasterField() { | ||
return masterField; | ||
} | ||
|
||
public void setMasterField(final String masterField) { | ||
this.masterField = masterField; | ||
} | ||
} | ||
|
||
@Entity | ||
public class ChildEntity extends MasterEntity { | ||
private String childField; | ||
|
||
@OneToMany(mappedBy = "childEntity") | ||
public Set<RelatedEntity> relatedEntitySet; | ||
|
||
public String getChildField() { | ||
return childField; | ||
} | ||
|
||
public void setChildField(final String childField) { | ||
this.childField = childField; | ||
} | ||
|
||
public Set<RelatedEntity> getRelatedEntitySet() { | ||
return relatedEntitySet; | ||
} | ||
|
||
public void setRelatedEntitySet(final Set<RelatedEntity> relatedEntitySet) { | ||
this.relatedEntitySet = relatedEntitySet; | ||
} | ||
} | ||
|
||
@Entity | ||
public class RelatedEntity { | ||
@Id | ||
@GeneratedValue | ||
public Long id; | ||
|
||
public String relatedField; | ||
|
||
@ManyToOne | ||
public ChildEntity childEntity; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getRelatedField() { | ||
return relatedField; | ||
} | ||
|
||
public void setRelatedField(final String relatedField) { | ||
this.relatedField = relatedField; | ||
} | ||
|
||
public ChildEntity getChildEntity() { | ||
return childEntity; | ||
} | ||
|
||
public void setChildEntity(final ChildEntity childEntity) { | ||
this.childEntity = childEntity; | ||
} | ||
} | ||
} |