java - 带返回列表 hibernate 的调用过程

标签 java mysql sql hibernate hql

我正在调用一个返回选择结果的过程。 我在 MySQL 中进行了测试,程序运行良好。

Call timeline_procedure(1)

但是当我从 hibernate 调用时,我收到错误

java.lang.IllegalArgumentException: 要遍历的节点不能为空!

调用该过程的代码是

    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();

最佳答案

不能用HQL,用SQL试试

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

关于java - 带返回列表 hibernate 的调用过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35139447/

相关文章:

java - Gson TypeAdapter的write方法即使设置字段不使用Expose序列化依然会被调用

php - 如何从 MySQL 显示特定 ID - 新手

彼此之间的php表格行

Java 对象 按字段名称设置字段值

google-app-engine - 如何使用 Java API 将超过 32Mb 的文件上传到谷歌云存储

java - 如何将 Map<Integer, List> 转换为 List

mysql - SELECT 标签和项目的关联

php - 从选择查询 php 返回结果数组

sql - 检查存储过程是否有效

php - 需要帮助为使用 MAMP 托管的本地 WordPress 导入 SQL 数据库