1

I am new in JPA so I made a small application. And in my app, I have a @Query like:

@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")

When application starts running, it gives the error:

Caused By: org.hibernate.hql.internal.ast.QuerySyntaxException: T_RBM_OPSCREENS_APPLICATIONS is not mapped [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] at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180) at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110) at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:93) at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:324) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3270) Truncated. see log file for complete stacktrace

But I did the Mapping like:

    @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;
.
.
.

What am I missing?

Thanks

1 Answer 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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the quick response. U are right about it, I saw the lines in the documentary, but the table above "T_SCR_APPS_OPS_ROLES" is not a model table so it has no model objects in my code. So the hql that u wrote was not completely right. Is there a way to use real table names with it?
No. The point of an ORM is to map relational tables to objects. If you don't do it, then use JDBC and SQL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.