Hibernate:HQL无法运行

时间:2016-10-25 04:40:31

标签: java sql hibernate

我在hibernate应用程序中使用 where 子句和编写了一个 SQL 查询。

这是方法,

public List<Comobility> getComobilityByIdComobilityItemsAndIdPatient(int idComobilityItems, int idPatient, Session session) {
    Query query = session.createQuery("from Comobility where comobility_items_idcomobility_items= :idComobilityItems and patient_idpatient= :idpatinet");
    query.setParameter("idComobilityItems", idComobilityItems);
    query.setParameter("idpatinet", idPatient);
    List<Comobility> list = query.list();
    return list;
} 

但这不起作用。没有任何异常或错误。实际上,没有任何结果。

有任何想法吗?

2 个答案:

答案 0 :(得分:1)

你应该尝试那样

  1. 使用try catch块包装你的方法。我相信查询有错误,然后它将进入catch块

    MyAppHtmlServiceProvider
  2. 确保您的方法参数不是<?php namespace MyApp\Html; use Illuminate\Html\HtmlServiceProvider; use MyApp\Html\MyAppHtmlBuilder; class MyAppHtmlServiceProvider extends HtmlServiceProvider { protected function registerHtmlBuilder() { $this->app->bindShared('html', function($app) { return new MyAppHtmlBuilder($app['url']); }); } }

  3. 检查您的清单是否为空。

  4. 要进行检查,您可以使用IDE调试器或在方法中添加一些日志。

答案 1 :(得分:0)

您需要检查日志中生成的SQL并对数据库执行它。如果编译了查询并且没有返回任何记录,则表示没有特定条件的记录。

要通过Hibernate生成SQL,请在hibernate配置中将属性show_sql设置为true