- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在存储库中(注意: SELECT_LIST
只是 from Organization org where in ( ... ) and in (...)
), IdentifiableWithName
就是Persistable
与 getName()
方法,使其成为一个投影。
@EntityGraph( Organization.NamedQuery.GRAPH_ID_NAME )
@Query( "select org " + SELECT_LIST + " order by org.name")
List<IdentifiableWithName> findOrganizationsForSelectList();
在实体上
@NamedEntityGraph( name = Organization.NamedQuery.GRAPH_ID_NAME, attributeNodes = {
@NamedAttributeNode( AbstractPersistedEntity.Index.ID ),
@NamedAttributeNode( Organization.Index.NAME ) }
)
但生成的查询似乎是实体的默认查询,而不是简化为仅名称、id 字段。这可能吗?如果是这样我做错了什么?如果 Spring Data 无法做到这一点,那么 JPA 是否可以(意味着这可能是一个可行的功能请求)?或者还有其他方法我可以做 @Query
到投影,或仅包含 id
的原始实体,和name
而不是任何其他字段或连接?
最佳答案
我假设您指的是一般意义上的投影,而不是 Spring Data JPA 的特定投影功能,该功能应该使您能够执行所需的操作:
Closed projections allow us to optimize the query execution as only exposed properties are queried from the data store.
http://docs.spring.io/spring-data/jpa/docs/1.10.1.RELEASE/reference/html/#projections
public interface IdentifiableWithName{
Long getId();
String getName();
}
interface SomeRepository extends CrudRepository<SomeClass, Long>{
@Query( "select org " + SELECT_LIST + " order by org.name")
List<IdentifiableWithName> findOrganizationsForSelectList();
}
关于java - 我可以将 @EntityGraph 应用于 @Query 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40851968/
我看过各种帖子,描述 JPA EntityGraph 允许在运行时选择图表。我不太清楚这指的是什么。 出于善意和尊重,我想引用这篇有用的文章:https://www.baeldung.com/jpa-
使用 EntityGraphs 时 JPA 1 级缓存如何工作? 如果我调用: Tool tool = toolRepository.findOne(id, CustomEntityGraph.fro
我使用 EclipseLink 2.6.3 作为 JPA 提供程序。我有两个实体: @Entity public class ClassA{ @Id private String uu
我创建了一个 util 方法: public Optional fetch(Class clazz, Object id, String... relations) { EntityGrap
我正在尝试让命名实体图正常工作。基本上,我有一个可以有零个或多个地址的客户。当我查询以获取客户列表时,我需要客户的字段,而不是关联的地址。当我查询特定客户时,我需要它的字段和所有关联的地址。所以,我一
我想使用 jpql 或 jpa 实体图加载相关实体。 似乎两者都做同样的事情。 我为什么要使用 实体图 而不是普通 jpql ?有什么好处吗? 使用jpql有什么区别: select distinct
当我有以下实体时。 @Entity class Article { @OneToMany Set comments; } @Entity class Comment { @ManyToOn
在存储库中(注意: SELECT_LIST 只是 from Organization org where in ( ... ) and in (...) ), IdentifiableWithName
我正在使用 JPA 使用 Spring Boot 开发应用程序。在应用程序中,我公开了一个休息 API。我不想使用 Spring data rest,因为我想完全控制数据。 我不知道如何动态使用 En
(我为这个问题做了一个SSCCE。) 我有 2 个简单的实体:Employee 和 Company。 Employee 与 Company 有一个 @ManyToOne 关系,采用默认获取策略(eag
(使用 Spring Data JPA)我有两个实体 Parent& Child,它们之间具有 OneToMany/ManyToOne 双向关系。我添加了 @NamedEntityGraph像这样的父
我正在尝试使用类型安全方法 EntityGraph.addAttributeNodes(Attribute ... attribute)用于构建我的实体图。我有一个带有 @MappedSupercla
我找到了这个 documentation关于实体图...阅读后,它让我想到您可以使用实体图来检索给定实体的 @Basic 字段的子集(直到现在,我已经使用用于检索关系的实体图,例如,加载员工[包括其所
我目前正在处理一个我无法解释的错误,所以我在这里寻求帮助。 我正在使用 Spring Data 获取我的对象,它们都由名为“FlagCMS”的列管理,如果设置为“S”,则意味着该对象不应链接到任何其他
我有用户实体: @ToString @Data @Entity @Table(name = "users") @NamedEntityGraph(name = "UserWithItems",
当我发现某些实体使用Hibernate Search ORM时,我试图消除不必要数据的加载。 。该框架提供的投影机制由于其局限性(例如,您需要的所有数据必须存储在索引中)而不太方便。 有没有办法使用E
我有一个与 ListingAttachment 具有一对多关系的 Listing 表。现在在整个应用程序中,每个表/实体都有 deleteFlag 并且每个存储库应该仅使用 deleteFlag 0
我有一个 Spring 应用程序。登录后,我将调用 getUserByEmail() 方法。 我只需要用户和角色数据。根据角色,我将显示不同的 View ,每个 View 都有不同的数据,需要不同的用
Spring Data JPA 是否有可能做到这一点?像这样: public interface UserDao extends CrudRepository { @EntityGraph(value
我见过各种描述JPA EntityGraph允许在运行时选择图形的帖子。我也不完全清楚这指的是什么。。出于诚意和尊重,我想将这篇有用的文章作为参考:https://www.baeldung.com/j
我是一名优秀的程序员,十分优秀!