[英]Spring Data JPA: How to fetch all entities of a specific type along with each entity's associated entities?
[英]How to fetch all entities which has createdAt parameter type Date by specific Month?
我有一个具有日期类型参数的 class。
class MyEntity {
@CreatedDate
@Column(nullable = false, updatable = false)
private Date createdAt;
}
如何检索 createdAt 为 ie: in May 的所有实体? 我需要使用@Query 还是有不同的方法来执行它?
我需要使用@Query 吗?
是的 )
如何检索 createdAt 为 ie: in May 的所有实体?
如果您的 JPA 提供程序是 Hibernate (我确定是这样),您可以在查询中使用month()
和其他有用的 HQL 函数:
@Query("select e from MyEntry e where month(e.createdAt) = ?1")
List<MyEntry> getAllByMonth(int month);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.