Search code examples
javamysqlsqlhibernatehql

Call procedure with return list hibernate


I am calling a procedure that return a result of a select's. I tested in MySQL and the procedure works fine.

Call timeline_procedure(1)

But when I call from hibernate I receive the error

java.lang.IllegalArgumentException: node to traverse cannot be null!

The code who call's the procedure is

    EntityManagerFactory emf = Persistence.createEntityManagerFactory(
            "Teste", properties);

    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    List<Timeline> result = em
            .createQuery("Call timeline_procedure(:accountId)", Timeline.class)
            .setParameter("accountId", accountId)
            .getResultList();
    em.getTransaction().commit();
    em.close();

Solution

  • You can't use HQL, just try with SQL

    List<Timeline> result = em
      .createSQLQuery("Call timeline_procedure(:accountId)")
      .addEntity(Timeline.class))
      .setParameter("accountId", accountId)
      .list();