简体   繁体   English

Toplink IN子查询

[英]Toplink IN subquery

I hava 2 objects associate by oneToMany relationship("One Model can have many events"). 我有2个对象通过oneToMany关系关联(“一个模型可以有很多事件”)。

I'm trying to make a subquery in ejbql to find models for one event, like this: 我正在尝试在ejbql中进行子查询,以查找一个事件的模型,如下所示:

SELECT model 
FROM RegModelValue model 
WHERE :event IN (model.events) 

.... but toplink doent recognize model alias and tell me "Internal Exception: line 1:129: unexpected token: model" ....但是toplink不会识别模型别名,并告诉我“内部异常:行1:129:意外令牌:模型”

Any ideas ? 有任何想法吗 ?

Thanks a lot by advance ! 非常感谢!

I think the order is wrong, the :event cannot be before a IN . 我认为顺序是错误的, :event不能在IN之前。

Try this : 尝试这个 :

    SELECT model 
    FROM RegModelValue model 
    JOIN model.events events
    WHERE events.id = :event

The syntax for your JPQL query should be: JPQL查询的语法应为:

SELECT model 
FROM RegModelValue model 
WHERE model.events IN (:event)

Below, the relevant section of the JPA 1.0 specification: 以下是JPA 1.0规范的相关部分:

4.6.8 In Expressions 4.6.8在表达式中

The syntax for the use of the comparison operator [NOT] IN in a conditional expression is as follows: 在条件表达式中使用比较运算符[NOT] IN的语法如下:

 in_expression ::= state_field_path_expression [NOT] IN ( in_item {, in_item}* | subquery) in_item ::= literal | input_parameter 

The state_field_path_expression must have a string, numeric, or enum value. state_field_path_expression必须具有字符串,数字或枚举值。 The literal and/or input_parameter values must be like the same abstract schema type of the state_field_path_expression in type. 文字和/或input_parameter值必须像相同抽象模式类型在类型state_field_path_expression的。 (See Section 4.12). (请参阅第4.12节)。

The results of the subquery must be like the same abstract schema type of the state_field_path_expression in type. 子查询的结果必须类似于state_field_path_expression类型中的相同抽象架构类型。 Subqueries are discussed in Section 4.6.15, “Subqueries”. 第4.6.15节“子查询”中讨论了子查询。

Examples are: 例如:

o.country IN ('UK', 'US', 'France') is true for UK and false for Peru , and is equivalent to the expression (o.country = 'UK') OR (o.country = 'US') OR (o.country = ' France') . o.country IN ('UK', 'US', 'France')UK为true,在Peru为false,等效于表达式(o.country = 'UK') OR (o.country = 'US') OR (o.country = ' France')

o.country NOT IN ('UK', 'US', 'France') is false for UK and true for Peru , and is equivalent to the expression NOT ((o.country = 'UK') OR (o.country = 'US') OR (o.country = 'France')) . o.country NOT IN ('UK', 'US', 'France')UK为false,在Peru为true,等效于表达式NOT ((o.country = 'UK') OR (o.country = 'US') OR (o.country = 'France'))

There must be at least one element in the comma separated list that defines the set of values for the IN expression. 逗号分隔列表中必须至少有一个元素定义了IN表达式的值集。

If the value of a state_field_path_expression in an IN or NOT IN expression is NULL or unknown, the value of the expression is unknown. 如果IN或NOT IN表达式中的state_field_path_expression的值为NULL或未知,则该表达式的值未知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM