【问题标题】:how to solve :Unable to build Hibernate SessionFactory Caused by: org.hibernate.HibernateException: Errors in named queries如何解决:无法构建 Hibernate SessionFactory 原因:org.hibernate.HibernateException:命名查询中的错误
【发布时间】:2020-04-24 15:39:57
【问题描述】:

我有一个命名查询

@NamedQuery(name = "Notification.findByyoungngAndInstNum",
        query = "SELECT n FROM Notification n WHERE n.institutionsregister.institutionnumber = ?1 and n.young is not null and n.date is null")

我想在我想添加年龄 >=25 岁的地方添加一个额外的检查

我试过了

SELECT n FROM Notification n WHERE n.institutionsregister.institutionnumber = ?1 and n.young is not null and age(current_date, n.young.dob) >= (interval '25' year)) and n.date is null

但在 jboss 中部署时出现错误。(无法构建 Hibernate SessionFactory 原因:org.hibernate.HibernateException:命名查询中的错误)

表名是: 通知 , 机构注册它具有字段机构编号, Young 表有字段 dob(出生日期)。

不知道如何构图。

【问题讨论】:

    标签: hibernate named-query


    【解决方案1】:

    这是一个替代解决方案,试试这个

    Calendar calendar = Calendar.getInstance();
          calendar.add(Calendar.YEAR, -25);
          Date dt =  calendar.getTime(); // use this as query argument, it can be dynamic
    
    
      SELECT n FROM Notification n WHERE n.institutionsregister.institutionnumber = ?1 and n.young is not null and n.date is null and n.young.dob < = ?2 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-24
      • 1970-01-01
      • 2018-03-22
      • 2015-05-19
      • 2017-04-10
      • 2021-10-18
      • 2018-07-25
      • 1970-01-01
      相关资源
      最近更新 更多