jOOQ子查询给出编译错误" SelectWhereStep ....类型中的(Condition ...)不适用于参数

时间:2015-11-10 14:21:06

标签: java mysql sql jooq

我在子查询的.where上收到以下编译器错误( .where(parentHelp.SUBJECT_ID = IFS_HELP.PARENT_SUBJECT_ID)):

  

SelectWhereStep< Record1< String>>类型中的(条件...)方法不适用于参数(TableField< IfsHelpRecord,Long>)

当我有以下jOOQ子查询代码时:

        IfsHelp parentHelp = IFS_HELP.as( "parentHelp" );

        Field<Object> parent_help_subject = sqlca   .select( IFS_HELP.SUBJECT_NAME )
                                                    .from( parentHelp )
                                                    .where( parentHelp.SUBJECT_ID = IFS_HELP.PARENT_SUBJECT_ID )
                                                    .asField( "parent_help_subject" );

        results = sqlca .select( IFS_HELP.SUBJECT_NAME, IFS_HELP.SUBJECT_ID, parent_help_subject )
                        .from( IFS_HELP )
                        .where( IFS_HELP.HELP_TEXT.like( argument ) )
                        .and( IFS_HELP.DISPLAY.equal( "Y" ) )
                        .orderBy( IFS_HELP.SUBJECT_NAME.asc() )
                        .limit( 50 )
                        .fetch();

数据库表如下所示:

IFS_HELP
  SUBJECT_ID (bigint, pk)
  SUBJECT_NAME (varchar)
  PARENT_SUBJECT_ID (bigint, fk back to ifs_help.subject_id)
  HELP_TEXT (varchar)
  DISPLAY (char)

这是我要执行的查询:

   SELECT         ifs_help.subject_name,   
                        ifs_help.subject_id,
                        ifs_isNull( ( select subject_name from ifs_help P where P.subject_id = ifs_help.parent_subject_id ), '' ) as parent_help_subject  
         FROM       ifs_help  
         WHERE      ifs_help.help_text like argument
            AND     ifs_help.display = 'Y'
         ORDER BY   ifs_help.subject_name ASC  
         LIMIT 50 

1 个答案:

答案 0 :(得分:0)

这是一个简单的拼写错误。如果在内部DSL中可以使用以下内容,例如jOOQ,那就太棒了:

.where( parentHelp.SUBJECT_ID = IFS_HELP.PARENT_SUBJECT_ID )
//                            ^ Redefined semantics of assignment operator

但事实并非如此。您无法在Java中重新定义赋值运算符的语义。因此,您必须使用eq()equal()方法:

.where( parentHelp.SUBJECT_ID.eq(IFS_HELP.PARENT_SUBJECT_ID) )