我有一个命名查询
@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:命名查询中的错误)
表名称为:通知,机构注册有现场机构编号,年轻表具有字段dob(出生日期)。
无法弄清楚如何构图。
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