【问题标题】:Query @ElementCollection in an @Entity with a Collection使用集合在 @Entity 中查询 @ElementCollection
【发布时间】:2016-03-11 08:48:54
【问题描述】:

假设我有一个@Entity (JPA 2.0)

@Entity    
class Entry {
        @ElementCollection
        Set<String> users = new HashSet();
        @ElementCollection
        Set<String> groups = new HashSet();
}

如何查询它以查找用户为“John”且组为“Foo”、“Bar”和“FooBar”的所有条目?

【问题讨论】:

  • 你会回答控制。

标签: java jpa jpql


【解决方案1】:

尝试使用类似的东西

@Query("SELECT DISTINCT e FROM Entry e WHERE :user MEMBER OF e.users AND :groups in e.groups")

List<Entry> yourQuery(@Param("user") String user, @Param("groups") List<String> groups);

【讨论】:

  • 谢谢,成功了!老实说,我之前尝试过,但是在带有 EclipseLink 2.3.1 的 Glassfish 3.1.2.2 上它不起作用。升级到 Payara 4.1 后,它就像一个魅力。
  • ":groups in e.groups" 对于标准 JPQL 无效。你不能做“收集收集”。请参阅 JPA 规范第 4.6.9 节
猜你喜欢
  • 1970-01-01
  • 2018-01-13
  • 1970-01-01
  • 2013-01-21
  • 1970-01-01
  • 2014-01-12
  • 1970-01-01
  • 2017-09-15
  • 2012-08-19
相关资源
最近更新 更多