In the two listed affects versions, a regression has been discovered which was not present in versions in the 4.3.x stream previous to these. The problem affects an entity domain with a three tier type hierarchy where the middle tier has a treated property and we are expecting to get back all of the root super-type in the from. Here is the test case to illustrate this:
public class Main
{
@Entity
public static abstract class Animal
{
@Id
@GeneratedValue
private Long id;
}
@Entity
public static abstract class Dog extends Animal
{
private boolean fast;
protected Dog(boolean fast)
{
this.fast = fast;
}
public final boolean isFast()
{
return fast;
}
}
@Entity
public static class Dachshund extends Dog
{
public Dachshund()
{
super(false);
}
}
@Entity
public static class Greyhound extends Dog
{
public Greyhound()
{
super(true);
}
}
@Test
public void treatAsSuperclassUsingCriteriaApi() {
EntityManager entityManager = getEntityManager();
EntityTransaction entityTransaction = entityManager.getTransaction();
entityTransaction.begin();
Greyhound greyhound = new Greyhound();
Dachshund dachshund = new Dachshund();
entityManager.persist(greyhound);
entityManager.persist(dachshund);
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Animal> criteriaQuery = cb.createQuery(Animal.class);
Root<Animal> animal = criteriaQuery.from(Animal.class);
Root<Dog> dog = cb.treat(animal, Dog.class);
criteriaQuery.where(cb.isTrue(dog.<Boolean>get("fast")));
List<Animal> results = entityManager.createQuery(
criteriaQuery).getResultList();
assertEquals(asList(greyhound), results);
entityTransaction.commit();
}
}
This results in no records found due to the query generated containing an odd addition restriction (1=2):
select main_anima0_.id as id2_0_, main_anima0_.fast as fast3_0_, main_anima0_.DTYPE as DTYPE1_0_ from Main$Animal main_anima0_ where 1=2 and main_anima0_.fast=1
On previous versions (e.g. 4.3.4), this same code generates the following correct query:
select main_anima0_.id as id2_0_, main_anima0_.fast as fast3_0_, main_anima0_.DTYPE as DTYPE1_0_ from Main$Animal main_anima0_ where main_anima0_.fast=1
|