Find @IdClass not working

Hello,
i have an entity with a composite primary key like this:

@IdClass(MyEntityKey.class)
public class MyEntity {

    @Id
    private Long id;
    @Id
    private OffsetDateTime bookDate;
    private String data;
}

and the ID-Class

public class MyEntityKey implements Serializable {

    private Long id;
    private OffsetDateTime bookDate;
}

After upgrading from hibernate-core from 6.2.1 to 6.2.4 (actually upgrade from Quarkus 3.0.3 to 3.1.1) the em.find() no longer works, but returns `null:

em.find(MyEntity.class, new MyEntityKey(ID, BOOK_DATE)); //returns null

but the same as a query works:

em
    .createQuery("SELECT x FROM MyEntity x WHERE x.id = :id AND x.bookDate = :bookDate", MyEntity.class)
    .setParameter("id", ID)
    .setParameter("bookDate", BOOK_DATE)
    .getResultList();
//returns the value

Any hints? Is this a known bug or should i create a ticket?

p.s. i found that the em.find() create SQL like this:

Hibernate: 
    select
        m1_0.bookDate,
        m1_0.id,
        m1_0.data 
    from
        MyEntity m1_0 
    where
        (
            m1_0.bookDate,m1_0.id
        ) in ((?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?),(?,?))

This is not what I expected…a IN-query for a find?!

1 Like

Looks like a batch size of 16 is configured for your app or some sort of batch fetch strategy. It would be great if you could try to reproduce this problem with our test case template (hibernate-test-case-templates/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub).

I tried to reproduce this with a JPAUnitTestCase - but here it works.
The differences between the JPAUnitTestCase and my Quarkus-Test are

  • I use postgres - the testcase H2
  • I use Quarkus 3.1.1 (containing hibernate-core 6.2.4.Final) …but there might be some special things in quarkus-hibernate-orm

i have to do some further investigations.
Do you have an example using postgres as DB in an JPAUnitTestCase ?

The use of PostgreSQL shouldn’t matter. Can you share a reproducer based on Quarkus and create a JIRA ticket for this in our issue tracker please?

I created Ticket HHH-16791.

1 Like