Is there a way to get Panache queries working in debugger using IntelliJ IDEA’s “Evaluate Query” function?

huangapple 未分类评论48阅读模式
英文:

Is there a way to get Panache queries working in debugger using IntelliJ IDEA’s “Evaluate Query” function?

问题

我几天前开始探索Quarkus和Panache,到目前为止,体验非常愉快。然而,我无法弄清楚如何在IntelliJ IDEA的“Evaluate Query”选项中运行Panache查询。

如果我使用 ./mvnw compile quarkus:dev 运行我的演示应用程序,所有定义的端点都能正常工作,并且响应预期的响应。例如,我的 ArticleResource 定义了一个方法,如下所示:

@Path("/article")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class ArticleResource {
    @GET
    public List<Article> getAll(@QueryParam @DefaultValue("0") Integer page) {
        return Article.findAll().page(Page.of(page, 2)).list();
    }
}

使用 curlhttp 查询时,返回的数据没有问题。然而,如果我将调试器连接到应用程序,将执行暂停在 getAll 方法中的断点,并在 Article.findAll().page(Page.of(page, 2)).list() 表达式上使用“Evaluate Expression”功能,会抛出异常。

异常类型是 java.lang.IllegalStateException,详细消息为 This method is normally automatically overridden in subclasses: did you forget to annotate your entity with @Entity?

我认为详细消息是一个误导,因为我的 Article 实体肯定已经用 @Entity 注解标记,相关的数据库表也已经创建。我尝试了两种将调试器连接到应用程序的方法:

  1. 定义一个自定义的 public static void main 方法,并像在IDEA中运行普通的Java应用程序一样运行应用程序。
  2. 让IDEA执行 compile quarkus:dev Maven 目标,并定义一个远程调试器连接。

这两种方法都会导致抛出相同的异常。似乎也不重要我尝试评估哪些Panache查询,即使是一个简单的 Article.listAll() 调用也会导致相同的异常。

我搜索了有关Maven工具、IDE集成和Panache的文档,但没有找到任何关于此问题的提及。当搜索异常详细信息时,大多数搜索结果都与人们在运行测试套件时遇到此问题有关,与调试器无关。

我尝试过的JDK是GraalVM EE 20.1.0(基于OpenJDK 11)。

希望我的解释是可以理解的,感谢您对此问题的任何见解!

英文:

I started exploring Quarkus and Panache a few days ago, and the experience has been a blast so far. However, I can’t figure out how to run Panache queries using the “Evaluate Query” option in IntelliJ IDEA.

If I run my demo application using ./mvnw compile quarkus:dev, all defined endpoints work properly and respond with the expected response. For example, my ArticleResource defines a method like so:

@Path(&quot;/article&quot;)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class ArticleResource {
    @GET
    public List&lt;Article&gt; getAll(@QueryParam @DefaultValue(&quot;0&quot;) Integer page) {
        return Article.findAll().page(Page.of(page, 2)).list();
    }
}

There is no problem with the data it returns when queried using curl or http. However, if I connect a debugger to the application, pause execution on a breakpoint in the getAll method and use the “Evaluate Expression” function on the Article.findAll().page(Page.of(page, 2)).list() expression, instead of database entities, an exception is thrown.

The exception type is java.lang.IllegalStateException, with a detail message of This method is normally automatically overridden in subclasses: did you forget to annotate your entity with @Entity?.

I think the detail message is a red herring because my Article entity is annotated with the @Entity annotation for sure, and a relevant database table is created as well. I tried two ways of attaching the debugger to my application:

  1. Define a custom public static void main method and run the app like a normal Java app from IDEA.
  2. Have IDEA execute the compile quarkus:dev Maven goals, and define a remote debugger connection.

Both of those approaches result in the same exception being thrown. It also doesn’t seem to matter which Panache queries I try to evaluate, even a simple Article.listAll() call fails with the same exception.

I searched the documentation on topics such as Maven tooling, IDE integration and Panache, but haven’t found any mention of this issue. When searched for the exception details, most search results are related to people having this issue when running a test suite, not related to the debugger.

The JDK I tried using is GraalVM EE 20.1.0 (based on OpenJDK 11).

I hope my explanation was understandable, and thank you for any insight into this issue!

huangapple
  • 本文由 发表于 2020年5月29日 09:20:46
  • 转载请务必保留本文链接:https://java.coder-hub.com/62077142.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定