JPA Mapping Query出错

时间:2013-01-04 09:15:34

标签: hibernate jpa spring-data

我是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] at   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;
.
.
.

我错过了什么?

由于

1 个答案:

答案 0 :(得分:4)

JPQL / HQL查询使用实体及其持久字段/属性/关联。他们不使用表格和列。

您的查询应该是:

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

阅读the documentation