- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个
@ElementCollection
@CollectionTable(
name = "orgattributes", joinColumns = @JoinColumn(name = "org_id"))
@MapKeyColumn(name = "attribute")
@Column(name = "value")
Map<String,String> attributes
如果对象在属性表中有给定条目,我想使用 JPQL
我在 Spring-Data 中尝试了以下(以及其他)都失败了
@Query("from Organization o join o.attributes a where ?1 in entry(a)")
List<Organization> findOrganizationsWithAttribute(Map.Entry<String,String> attributeValue) ;
default List<Organization> findOrganizationsWithAttribute(String attribute, String value) {
return findOrganizationsWithAttribute(Map.entry(attribute, value));
}
使用 map
@Query("from Organization o join o.attributes a where ?1 in entry(a)")
List<Organization> findOrganizationsWithAttribute(Map<String,String> attributeValue) ;
default List<Organization> findOrganizationsWithAttribute(String attribute, String value) {
return findOrganizationsWithAttribute(Map.of(attribute, value));
}
我原来的一个在只有一个属性的情况下有效。
@Query("from Organization o join o.attributes a where key(a) = ?1 and value(a) = ?2")
List<Organization> findOrganizationsWithAttribute(Map<String, String> attributeValue);
我想做的 SQL 等效项是
select * from organization o where o.orgid in (select orgid from orgattribute a where a.attribute = ?1 and a.value = ?2)
最佳答案
使用List
或Set
执行此操作的标准方法是MEMBER OF
。我从未尝试过使用Map
。但你可以尝试一下
@Query("SELECT o FROM Organization o where ?1 MEMBER OF o.attributes")
尝试使用 map 的键或值作为参数值。 key 可能有效。
关于java - 检查 ElementCollection 映射是否有匹配的条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59584088/
public enum ReportStatus { SUCCCEED, FAILED; } public class Work { @ElementCollection @E
如何使用 JPQL 通过 ElementCollections 查询 JPA 实体,其中 ElementCollection 包含给定元素集中的所有元素? 例如,如果 Node 实体定义了“属性”的
我的目标是克隆实体“产品”及其所有过滤器。 例如,我有一个实体(为简单起见,省略了 getter 和 setter): @Entity public class Product { @Id
我有一个这样声明的“标签”属性: @Entity public class BlogArticle { [...] @ElementCollection(fetch = FetchTy
我有 JavaEE 应用程序并使用 Hibernate 4.3.7.Final。在我的数据库中有两个表:RECHT(包含列:RECHT_RECHTEART(VARCHAR)和GEOB_ID(NUMBE
我想减少 spring 运行的查询量。当通过 SQL 获取带有 @ElementCollection 的对象时,我想直接通过查询中的 JOIN 获取 ElementCollections 的数据。 具
我使用 Hibernate 3.5.6 作为我的 JPA 2.0 实现。我正在尝试在我的实体中构建一个 @ElementCollection(省略了许多字段): @Entity public clas
我有一个包含元素集合的实体类 PositionOrdering: @ElementCollection(targetClass = Position.class, fetch = FetchType.
我有一个多对多关系,它为项目分配标签(除了字符串之外什么都没有): +------+ +------------+ +-------+ | ITEM | | ITEM_LABEL |
我有一个 @Entity命名 Video ,它包含 @ElementCollection标签: @Entity @Table(name = "videos") public class Video {
我试图弄清楚如何使用枚举列表(@ElementCollection)对实体进行 DTO 投影。不幸的是,缺少 QueryDsl 文档,在这里我只能找到版本 3 的结果 不是 适用于版本 4。 @Ent
我有一个具有不同字段的实体: @Entity public class TestEntity { private int id; private String name; pr
给定一个实体产品 @Entity public class Product { private Long id; private List reviews; public Pr
我的数据库中有两个表,如下所示,外键来自 job_label.job_id到 job_record 中的等效列。此外,job_id 的三元组, label_key ,和label在job_record
我有一个具有不同字段的实体: @Entity public class TestEntity { private int id; private String name; pr
我有一个 @ElementCollection @CollectionTable( name = "orgattributes", joinColumns = @JoinColumn(name =
我有一个 User 类,可以有多个登录名: @Entity public class User { @ElementCollection private List logins = new A
对于这个问题,请考虑以下示例: @Entity public class File { public static enum Permission { READABLE, WRITEABLE,
无论如何,我可以在没有这个注释的情况下获得 @ElementCollection 的效果吗?我使用的是 Hibernate 3.3,而 @ElementCollection 和 @Collection
我有以下实体,对此示例进行了简化: @Entity public class Subscription { @Column private String user; @Column
我是一名优秀的程序员,十分优秀!