我是JPA中的新成員,所以我創建了一個小應用程序。而在我的應用程序,我有一個像@Query:JPA映射查詢給出錯誤
@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")
當應用程序開始運行時,它給人的錯誤:
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
但我做了映射,如:
@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;
.
.
.
我錯過了什麼?
謝謝
感謝您的快速響應。 U是正確的,我看到了紀錄片中的行,但上面的表「T_SCR_APPS_OPS_ROLES」不是一個模型表,所以它沒有我的代碼中的模型對象。所以你寫的hql並不完全正確。有沒有辦法使用真正的表名與它? – Neron
否。ORM的要點是將關係表映射到對象。如果你不這樣做,那麼使用JDBC和SQL。 –