-1

I tried this code

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

but I have this error

 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.

what is the problem ?

4

2 回答 2

3

请参阅JPQL 语言参考的第 10.2.5.8 段。它应该看起来像where c.id in (1)

于 2013-07-22T11:52:02.027 回答
1

以下是文档中 IN 谓词的 JPQL 兼容示例。

  1. select p from Payment p where type(p) in (CreditCardPayment, WireTransferPayment)

  2. select c from Customer c where c.hqAddress.state in ('TX', 'OK', 'LA', 'NM')

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

  4. select c from Customer c where c.hqAddress.state in ( select dm.state from DeliveryMetadata dm where dm.salesTax is not null )

选项 2. 似乎您正在寻找什么,您可以尝试以下查询。

SELECT c FROM Category c where c.id in (1)

但是,如果您给出恒定的单个值,为什么您不使用它=

于 2013-07-22T11:54:58.727 回答