Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用JPA查找其鸟日为今天的用户_Java_Hibernate_Orm_Jpa_Jpql - Fatal编程技术网

Java 使用JPA查找其鸟日为今天的用户

Java 使用JPA查找其鸟日为今天的用户,java,hibernate,orm,jpa,jpql,Java,Hibernate,Orm,Jpa,Jpql,我有一张有用户的表格,正在尝试获取一张有今天过生日的人的名单,这样应用程序就可以发送电子邮件 用户被定义为 @Entity public class User { @Size(max = 30) @NotNull private String name; [...] @Temporal(TemporalType.DATE) @DateTimeFormat(style = "S-") protected Date birthday; }

我有一张有用户的表格,正在尝试获取一张有今天过生日的人的名单,这样应用程序就可以发送电子邮件

用户被定义为

@Entity
public class User {

    @Size(max = 30)
    @NotNull
    private String name;

    [...]
    @Temporal(TemporalType.DATE)
    @DateTimeFormat(style = "S-")
    protected Date birthday;
}
我有一个方法可以返回今天出生的人

@SuppressWarnings("unchecked")
public static List<User> findUsersWithBirthday() {

 List<User> users = 
  entityManager().createQuery("select u from User u where u.birthday = :date")
    .setParameter("date", new Date(), TemporalType.DATE)
    .getResultList();
  return users;
}
然而,我一直在努力寻找一个类似的JPA


我正在使用Spring 3.0.1和Hibernate 3.3.2,我不知道如何在JPQL中做到这一点,但HQL有
day()
month()函数,因此您可以运行:

from User u 
where day(u.birthday) = day(CURRENT_DATE) 
and month(u.birthday) = month(CURRENT_DATE) 
如果使用HQL不是一个选项,我会选择本机查询

from User u 
where day(u.birthday) = day(CURRENT_DATE) 
and month(u.birthday) = month(CURRENT_DATE)