2013-07-22 83 views
-1

我想这个代码如何在JPQL中使用in子句?

Query q = em.createQuery("SELECT c FROM Category c where c.id in 1"); 

,但我有这个错误

An exception occurred while creating a query in EntityManager: 
    Exception Description: Syntax error parsing [SELECT c FROM Category c where c.id in 1]. 
    [31, 40] The expression is not a valid conditional expression. 

是什么问题?

回答

1

下面是来自文档的IN谓词的JPQL兼容示例。

  1. 从付款p选择p其中式(P)中(类:CreditCardPayment, WireTransferPayment)

  2. 从客户c选择c其中c.hqAddress.state在( 'TX', 'OK', 'LA','NM')

  3. select c from Customer c where c.hqAddress.state in?

  4. 从客户c选择c其中c.hqAddress.state在( 选择dm.state 从DeliveryMetadata DM 其中dm.salesTax不为null)

选项2似乎你是什么寻找,你可以尝试下面的查询。

SELECT c从C类,其中c.id(1)

但是,如果你为什么不使用=而不是给定一个值。