HHH-9646 add a test showing the issue is resolved

This commit is contained in:
Gavin 2022-12-25 23:28:59 +01:00 committed by Gavin King
parent 169b9a849c
commit 0f29c15461
4 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package org.hibernate.orm.test.filter.subclass.joined2;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.Table;
import org.hibernate.annotations.Filter;
import static jakarta.persistence.InheritanceType.JOINED;
@Entity
@Table(name = "animals")
@Inheritance(strategy = JOINED)
@Filter(name = "companyFilter", condition = "id_company = :companyIdParam")
public class Animal {
@Id
@Column(name = "id_animal")
private int id;
private String name;
@Column(name = "id_company")
private long company;
}

View File

@ -0,0 +1,16 @@
package org.hibernate.orm.test.filter.subclass.joined2;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.PrimaryKeyJoinColumn;
import jakarta.persistence.Table;
@Entity
@Table(name = "dogs")
@PrimaryKeyJoinColumn(name = "id_dog", referencedColumnName = "id_animal")
public class Dog extends Animal {
private String breed;
@ManyToOne @JoinColumn(name = "id_owner")
private Owner owner;
}

View File

@ -0,0 +1,30 @@
package org.hibernate.orm.test.filter.subclass.joined2;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.ParamDef;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNull;
@TestForIssue(jiraKey = "HHH-9646")
@SessionFactory
@DomainModel(annotatedClasses = {Animal.class, Dog.class, Owner.class, JoinedInheritanceFilterTest.class})
@FilterDef(name = "companyFilter", parameters = @ParamDef(name = "companyIdParam", type = long.class))
public class JoinedInheritanceFilterTest {
@Test public void test(SessionFactoryScope scope) {
scope.inTransaction( s -> {
s.createQuery("SELECT o FROM Owner o INNER JOIN FETCH o.dog d WHERE o.id = 1").getResultList();
s.enableFilter("companyFilter").setParameter("companyIdParam", 2l).validate();
s.createQuery("SELECT o FROM Owner o INNER JOIN FETCH o.dog d WHERE o.id = 1").getResultList();
s.createQuery("FROM Animal").getResultList();
s.createQuery("FROM Dog").getResultList();
assertNull( s.find(Owner.class, 1) );
assertNull( s.find(Animal.class, 1) );
assertNull( s.find(Dog.class, 1) );
});
}
}

View File

@ -0,0 +1,30 @@
package org.hibernate.orm.test.filter.subclass.joined2;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import org.hibernate.annotations.Filter;
@Entity
@Table(name = "owners")
@Inheritance(strategy = InheritanceType.JOINED)
@Filter(name = "companyFilter", condition = "id_company = :companyIdParam")
public class Owner {
@Id
@Column(name = "id_owner")
private int id;
private String name;
@ManyToOne
@JoinColumn(name = "id_dog")
private Dog dog;
@Column(name = "id_company")
private long company;
}