承認我有一個類,看起來像這樣:JPQL:Postgres的實體不與TABLE_PER_CLASS繼承
@Entity(name="DashboardWidget")
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class DashboardWidget
{
public enum Type {USER_COUNT, ...};
@Column(name="COMPANY_ID")
protected Long companyId;
@Enumerated(EnumType.STRING)
protected Type type;
...
有了這個實體後面沒有表。這些表存在於每個子類實體中。這些類是這樣的:
@Entity
@Table(name = "WIDGET_USER_COUNT")
public class UserCountWidget extends DashboardWidget
{
...
藉助於Spring數據JPA,我有我的倉庫以下:
List<DashboardWidget> findByCompanyId(Long companyId);
這個偉大的工程,並在列表中包含了不同的子conrete類的實例。然後我有一個用例,我只想要Type
枚舉中的Set
,這樣我就不必加載完整的實體。所以,我說這對我的春節,數據倉庫:
@Query("SELECT w.type FROM DashboardWidget w WHERE w.companyId = :companyId")
Set<DashboardWidget.Type> getWidgetTypes(@Param("companyId") Long companyId);
然而,當這個被調用,我得到以下錯誤:
Internal Exception: org.postgresql.util.PSQLException: ERROR: relation "dashboardwidget" does not exist
Position: 18
Error Code: 0
Call: SELECT TYPE FROM DASHBOARDWIDGET WHERE (COMPANY_ID = ?)
bind => [8888810010000000000]
Query: ReportQuery(referenceClass=DashboardWidget sql="SELECT TYPE FROM DASHBOARDWIDGET WHERE (COMPANY_ID = ?)")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:682)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2002)
at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:250)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2738)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllReportQueryRows(ExpressionQueryMechanism.java:2675)
at org.eclipse.persistence.queries.ReportQuery.executeDatabaseQuery(ReportQuery.java:848)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1127)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:403)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1215)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1786)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1751)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
... 99 more
Caused by: org.postgresql.util.PSQLException: ERROR: relation "dashboardwidget" does not exist
Position: 18
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:83)
at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:83)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:1007)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:642)
... 119 more
我不知道JPQL不夠好,知道它的一些與我的查詢有關的信息,或者Spring Data爲使findByCompanyId
方法起作用而做的某種魔術。有什麼我可以做的,使getWidgetTypes
方法的工作?
由於Eclipselink正在查詢DashboardWidget描述符,所以看起來像一個錯誤。您使用的是哪個EclipseLink版本? – Chris
@Chris Eclipselink版本2.5.2 – dnc253