Given
* Entity with @ManyToOne attribute
When
* Executing HQL with subquery using @ManyToOne attribute
Then
* Wrong query is generated and wrong results are returned
{code:java}@Entity @Table(name = "ENTITY_A") public class EntityA {
@Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "ID") Integer id;
@Column(name = "PROPERTY_A") int propertyA;
@ManyToOne @JoinColumn(name = "REFERENCE") EntityA reference; }{code}
{code:java} @Test public void hhhXXXXTest() throws Exception { // BaseCoreFunctionalTestCase automatically creates the SessionFactory and // provides the Session. try (Session s = openSession()) { Transaction tx = s.beginTransaction(); EntityA entityA1 = new EntityA();
s.persist(entityA1); s.flush();
Query<EntityA> query = s.createQuery( "select c from EntityA c where c.propertyA = (select max(e.propertyA) from EntityA e where (c.reference is null and e.reference is null))", EntityA.class); List<EntityA> actual = query.list(); assertThat(actual).hasSize(1); tx.commit(); } }{code}
{noformat}Hibernate: select e1_0.ID, e1_0.PROPERTY_A, e1_0.REFERENCE from ENTITY_A e1_0 where e1_0.PROPERTY_A=( select max(e2_0.PROPERTY_A) from ENTITY_A e2_0, ENTITY_A r1_0 where ( r1_0.ID is null and e2_0.REFERENCE is null ) and r1_0.ID=e1_0.REFERENCE ){noformat}
{noformat}java.lang.AssertionError: Expected size:<1> but was:<0> in: <[]>{noformat}
Failing test scenario to be attached and also available here [https://github.com/ratoaq2/HHH-16397|https://github.com/ratoaq2/HHH-16397|smart-link] |
|