1

我是 JPA 的新手,所以我做了一个小应用程序。在我的应用程序中,我有一个 @Query,例如:

@Query("select a from T_RBM_OPSCREENS_APPLICATIONS a, T_SCR_APPS_OPS_ROLES b where a.id=b.app_id and b.role_id=?1")

当应用程序开始运行时,它会给出错误:

引起:org.hibernate.hql.internal.ast.QuerySyntaxException:T_RBM_OPSCREENS_APPLICATIONS 未映射 [从 T_RBM_OPSCREENS_APPLICATIONS a,T_SCR_APPS_OPS_ROLES b 中选择 a.id=b.app_id 和 b.role_id=?1] 在 org.hibernate.hql .internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180) 在 org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110) 在 org.hibernate.hql.internal.ast .tree.FromClause.addFromElement(FromClause.java:93) 在 org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:324) 在 org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker .java:3270) 被截断。查看日志文件以获取完整的堆栈跟踪

但我做了这样的映射:

    @Entity
    @Table(name = "T_RBM_OPSCREENS_APPLICATIONS", schema = "RBMCORE")
    public class Application implements Serializable{

        @Id

        @Column(name = "id")
        private int id;

        @Column(name = "s_appname", unique = true, nullable = false)
        private String name;
.
.
.

我错过了什么?

谢谢

4

1 回答 1

4

JPQL/HQL queries use entities and their persistent fields/properties/associations. They don't use tables and columns.

Your query should be something like:

select a from Application a inner join a.roles role where role.id = ?1

Read the documentation.

于 2013-01-04T09:20:26.107 回答