JPA 2和Hibernate 3.5.1成员查询不起作用

JPA 2和Hibernate 3.5.1成员查询不起作用,第1张

JPA 2和Hibernate 3.5.1成员查询不起作用

您的查询对我来说 很好 。作为记录,这是JPA 2.0规范关于

MEMBER OF
*** 作符的内容:

4.6.13集合成员表达式
> `MEMBER OF`在collection_member_expression中使用比较运算符的语法如下:>  >  >        collection_member_expression ::=>      entity_or_value_expression [NOT] MEMBER [OF]> collection_valued_path_expression>        entity_or_value_expression ::=>      single_valued_object_path_expression |>      state_field_path_expression |>      simple_entity_or_value_expression>        simple_entity_or_value_expression ::=>      identification_variable |>      input_parameter |>      literal

表达式测试指定的值是否是由集合值的路径表达式指定的集合的成员。

集合成员表达式中不支持评估为可嵌入类型的表达式。在本规范的将来版本中,可能会添加对在集合成员表达式中使用可嵌入对象的支持。

如果集合值的路径表达式指定一个空集合,则

MEMBER
OF表达式
FALSE
的值为,而
NOT MEMBER OF
表达式的值为
TRUE
。否则,如果集合成员表达式中的collection_valued_pa​​th_expression或Entity_or_value_expression的值为NULL或未知,则集合成员表达式的值为未知。

例:

>     SELECt p>     FROM Person p>     WHERe 'Joe' MEMBER OF p.nicknames

因此,由于在查询中看不到任何错误,因此我已经使用Eclipselink 1测试了您的代码,以下代码段也可以正常工作:

Query query = em.createQuery("SELECt u FROM User u WHERe 'admin' MEMBER OF u.roles");List list = query.getResultList();

但是,使用Hibernate EntityManager
3.5.1-Final确实失败。这听起来像个错误,请随时提出有关Jira的问题。

1为了以防万一,我使用了以下Maven配置文件(用于JPA提供程序):

  <profile>    <id>eclipselink</id>    <repositories>      <repository>        <id>eclipselink</id>        <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo/</url>      </repository>    </repositories>    <dependencies>      <!-- See http://wiki.eclipse.org/Eclipselink/Maven -->      <dependency>        <groupId>org.eclipse.persistence</groupId>        <artifactId>eclipselink</artifactId>        <version>2.0.0</version>      </dependency>      <!-- optional - only needed if you are using JPA outside of a Java EE container-->      <dependency>        <groupId>org.eclipse.persistence</groupId>        <artifactId>javax.persistence</artifactId>        <version>2.0.0</version>        <scope>provided</scope>      </dependency>       </dependencies>  </profile>

这是我的

persistence.xml

    <?xml version="1.0" encoding="UTF-8"?>    <persistence        xmlns="http://java.sun.com/xml/ns/persistence"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"        version="2.0">      <persistence-unit name="TestPu" transaction-type="RESOURCE_LOCAL"> <class>com.stackoverflow.q2688144.User</class> <properties>          <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>          <property name="javax.persistence.jdbc.url" value="jdbc:derby:testdb;create=true"/>   <property name="eclipselink.target-database" value="DERBY"/>          <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>        </properties>      </persistence-unit>    </persistence>

更新:
在HHH-5209中报告



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5048099.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存