如何修复控件查询持久性 QL(hql)

How fix control Query Persistence QL(hql)

我的 Hibernate 查询有问题,我的 IDE检查错误语法:

This inspection controls whether the Persistence QL Queries are error-checked

但是我在 hibernate.cfg.xml:

中为 Task 个对象创建映射
<session-factory>
    <property name="connection.url">jdbc:postgresql://localhost:5432/todo_list</property>
    <property name="connection.driver_class">org.postgresql.Driver</property>
    <property name="connection.username">postgres</property>
    <property name="connection.password">1</property>
    <property name="dialect">org.hibernate.dialect.PostgreSQL95Dialect</property>

    <mapping resource="ru/pravvich/model/Task.hbm.xml" />
</session-factory>

方面:

如果我作弊 IDE 而不是 createQuery("select t from Task t"),创建变量并推入 createQuery

String hql = format("select t from Task t where t.id > %s", 0); session.createQuery(hql)

它可以工作,但不是普通代码。如何解决这个问题

IDEA 无法识别您正在使用的描述符。检查项目结构 -> Facets -> Hibernate。您应该已经在 Descriptors 中找到了一个 cfg.xml 文件。如果您通过 spring 会话工厂定义使用包扫描,您应该已经找到一个会话工厂 bean。如果两者都不存在,您可以添加一个。

以下是我解决相同问题的方法: 在 IDEA 首选项 (Settings)/Editor/Language Injections 中打开并在语言列表下找到 Session (org.hibernate)。 在语言列下,应选择 Hibernate QL。 双击它,将显示一个操作列表。 Select 您需要的操作。