- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试运行 JPA 查询以仅返回实体中的特定字段,而不是整个实体(出于性能原因)。
在这个实体中是这样的:
@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "helper", fetch = FetchType.EAGER)
@MapKeyColumn(name = "year")
public Map<Integer, DutyHistory> getDutyHistoryList() {
return dutyHistoryList;
}
我想在我的查询中从该 map 返回多个值,例如过去 3 年 DutyHistory 对象中的字段。
我的问题是,这个查询语法是什么?我将返回值映射到 POJO,如下所示:
@Query(value = "SELECT new com.castlemon.helpers.dto.ReportHelper(h.helperId, h.firstName, h.secondName"
+ ", h.sex, h.service, h.dateOfBirth, h.schoolGroup, h.orientationRequired, h.notes as adminNotes "
+ ", h.primaryDuty.dutyName as primaryDuty, h.secondDuty, h.secondaryDuty.dutyName as secondaryDuty "
+ " WHERE h.travelling = 1")
public List<ReportHelper> getTravellingHelperDetails();
最佳答案
您应该使用“年份”参数创建另一个查询
@Query(value = "SELECT new com.castlemon.helpers.dto.ReportHelper(h.helperId, h.firstName, h.secondName"
+ ", h.sex, h.service, h.dateOfBirth, h.schoolGroup, h.orientationRequired, h.notes as adminNotes "
+ ", h.primaryDuty.dutyName as primaryDuty, h.secondDuty, h.secondaryDuty.dutyName as secondaryDuty "
+ " WHERE h.travelling = 1 AND h.year >= :yearLimit")
public List<ReportHelper> getTravellingHelperDetailsUntilYear(String yearLimit);
关于java - JPA @OneToMany : Returning only some values from map in a query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34419689/
我有如下三个实体相关:A(一对多) B(一对多) C我如何从 C 中获取基于 A->id 的所有记录?????? 最佳答案 类似于: $entityManager = $this->getDoctri
代码之间有什么区别? @LazyCollection(LazyCollectionOption.FALSE) @OneToMany(mappedBy = "siteesTypeSite", casca
public class ClientEntity { @Id @Column(name="id", nullable = false, unique = true) @Gen
现在,我明白这是不可能的,但我无法想象这是一个从未遇到过的问题。 我在不同的 PU 中有两个实体。我想从一个外键到另一个。我想知道谁已经遇到过这个问题,他们是否找到了一个好的解决方案? 最佳答案 Ec
我有两个与 OneToMany - ManyToOne 映射关联的类。当我选择父实体时,它也会选择子实体,但是分配给它的所有子实例都是每个父实例,而不是分配相关实例。 采购入口.java @Entit
我在 OneToMany 字段的持久性方面遇到了麻烦。这是两个简化的类 我是用来做测试的。 public class User implements Serializable { ... privat
我有一个持久化实体,它有一个 @OneToMany另一个实体的列表,我需要列表顺序才能由用户编辑,这非常有效。我可以完全重新排序内存中的 java 列表,当我 save() 对象时,链接表中的链接顺序
我是 Hibernate 的新手,正在尝试一些应该很容易的事情,但我无法让它工作。 有两个表,一个人和一个地址。一个人可以有一个或多个地址,即:一个 OneToMany 映射。当我尝试将相同的地址添加
我有双向、一对多和多对一的关系。说,一个公司有很多人,一个人有一个公司,所以,在公司中, @OneToMany(mappedBy = "company", fetch = FetchType.EAGE
在JPA中设置一对多关系时如何设置外键的列名? 我想将“items_id”的名称更改为“item_id” @OneToMany private List items; 我尝试了以下注释但没有成功: @
我有2张 table : 第一个是“人”: person_id, 人名 第二个是“PersonsGraphs”: person_id1, person_id2, 关系类型 我正在寻找一种建立“家谱”的
请帮我解决这个问题。我尝试了很多组合,但似乎没有任何效果。我正在尝试使用注释实现 hibernate 映射,但在保存我的父对象及其子对象期间,我注意到正在调用更新语句而不是插入语句。 我有两个彼此具有
我是 JPA 新手。假设我有这两个实体: //Imports @Entity @Table(name="article", schema = "sch_client") public class Ar
我有使用 Hibernate 归档 @ManyToOne 关系的代码。我有两个类 Package 和 Address。在 Address 中,我希望有唯一的条目,其中每个地址都与其他地址有所不同。然后
在订单表中插入时遇到此错误 org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to
我是 Hibernate 新手,我正在尝试在 Person 和 Vehicle 类之间建立 OneToMany/ManyToOne 双向关系。在我的示例中,一个人可以拥有许多车辆,而一辆车辆只属于一个
我们是 JPA 新手,尝试建立一个非常简单的一对多关系,其中名为 Message 的 pojo 可以具有由名为 GROUP_ASSOC 的联接表定义的整数组 id 列表。 。这是 DDL: CREAT
我在使用 JPA 时遇到了一些小问题。我有三个表(OTHER 表与此处无关,但我添加它只是为了解释为什么存在没有 PK 的表 USERS): ADDRESS id (PK) user_id (FK)
请帮我解决这个问题。我尝试了很多组合,但似乎没有任何效果。我正在尝试使用注释实现 hibernate 映射,但在保存我的父对象及其子对象期间,我注意到正在调用更新语句而不是插入语句。 我有两个彼此具有
我的 Task 实体表示为: @Entity @Getter @NoArgsConstructor public class Task { @Id @GeneratedValue(st
我是一名优秀的程序员,十分优秀!