WHERE 上的 GQL 错误

发布于 2024-10-16 05:50:42 字数 730 浏览 1 评论 0原文

select from comments.Comment 
where ownerType == 'looks.Look' 
AND ownerName == 'Yakuza' order by date

我得到异常:

Portion of expression could not be parsed: AND ownerName == 'Yakuza'

虽然这个查询工作得很好:

select from comments.Comment 
where ownerType == 'looks.Look' 
order by date

这也是:

select from comments.Comment 
where ownerName == 'Yakuza' order by date

完整的代码:

PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "... query goes here ...";
List<Comment> comments = null;
try {
    comments = (List<Comment>) pm.newQuery(query).execute();
}
...
select from comments.Comment 
where ownerType == 'looks.Look' 
AND ownerName == 'Yakuza' order by date

I get exception:

Portion of expression could not be parsed: AND ownerName == 'Yakuza'

While this query works nice:

select from comments.Comment 
where ownerType == 'looks.Look' 
order by date

And this too:

select from comments.Comment 
where ownerName == 'Yakuza' order by date

The full code:

PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "... query goes here ...";
List<Comment> comments = null;
try {
    comments = (List<Comment>) pm.newQuery(query).execute();
}
...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

下壹個目標 2024-10-23 05:50:42

将“AND”替换为“&&”

  PersistenceManager pm = PMF.get().getPersistenceManager();
  try {
    Query query = pm.newQuery("select from " + Song.class.getName()
        + " where mArtist== '" +artist+
        "' &&  mTitle=='"+title+
        "' &&  mAlbum=='"+album+"'" );
    List<Song> list = (List<Song>) query.execute();
  } catch (RuntimeException e) {
    System.out.println(e);
    throw e;
  } finally {
    pm.close();
  }

Replace "AND" with "&&"

  PersistenceManager pm = PMF.get().getPersistenceManager();
  try {
    Query query = pm.newQuery("select from " + Song.class.getName()
        + " where mArtist== '" +artist+
        "' &&  mTitle=='"+title+
        "' &&  mAlbum=='"+album+"'" );
    List<Song> list = (List<Song>) query.execute();
  } catch (RuntimeException e) {
    System.out.println(e);
    throw e;
  } finally {
    pm.close();
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文