jpa 调用只读复合表,但收到“异常描述:缺少 [CollectorInfo] 的描述符”
在 Spring 3 应用程序中,控制器调用 JpaCollectorManager 并调用 JpaCollectorInfoDao 来获取由本机查询定义的列表。该查询调用 2 个使用 sql 和 jpql 的单独表,因为我需要使用 jpql 中未实现的 postgresql 功能。当控制器尝试归档列表时,我收到以下错误消息:
异常 [EclipseLink-6007](Eclipse 持久性服务 - 2.1.2.v20101206-r8635):org.eclipse.persistence.exceptions.QueryException 异常描述:缺少 [CollectorInfo] 的描述符。
查询:ReadAllQuery(referenceClass = CollectorInfo sql =“选择不同的ON(col.collector_id,pst.process_source_type)col。*,pst.process_source_timestamp,pst.process_source_type来自perform_schema.collector col加入perform_schema.process_set pst on pst.collector_id = col。 Collector_id 顺序按 col.collector_id、pst.process_source_type、pst.process_source_timestamp desc ")
控制器 Java 有以下调用:
List<CollectorInfo> ps = this.collectorInfoManager.getLatestCollectorInfo();
JpaCollectorInfoManager.java 有:
public List<CollectorInfo> getLatestCollectorInfo()
{
return collectorInfoDao.getLatestCollectorInfo();
}
JpaCollectorInfoDao.java:
@Override
@Transactional
public List<CollectorInfo> getLatestCollectorInfo() {
Query query = entityManager.createNativeQuery( ( "select distinct ON ( col.collector_id," +
"pst.process_source_type ) " +
"col.*," +
"pst.process_source_timestamp," +
"pst.process_source_type " +
"from perform_schema.collector col " +
"join perform_schema.process_set pst " +
"on pst.collector_id = col.collector_id " +
"order by col.collector_id, " +
"pst.process_source_type," +
"pst.process_source_timestamp desc " ),
CollectorInfo.class );
return ( (List<CollectorInfo>) query.getResultList() );
}
CollectorInfo 类没有定义 @Entity。如果我设置定义的@Entity,那么它告诉我该表无法解析(这是正确的,因为没有实际的表)。我已经尝试了各种排列,但似乎无法制作这根针线。
In a Spring 3 app a controller is calling a JpaCollectorManager with calls a JpaCollectorInfoDao to get a list which is defined by a nativequery. The query calls 2 seperate tables which uses sql and jpql because I need to use a postgresql feature not implemented in jpql. When the controller tries to file the list I get the following error message:
Exception [EclipseLink-6007] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.QueryException
Exception Description: Missing descriptor for [CollectorInfo].
Query: ReadAllQuery(referenceClass=CollectorInfo sql="select distinct ON ( col.collector_id,pst.process_source_type ) col.*,pst.process_source_timestamp,pst.process_source_type from perform_schema.collector col join perform_schema.process_set pst on pst.collector_id = col.collector_id order by col.collector_id, pst.process_source_type,pst.process_source_timestamp desc ")
The controller Java has the following call:
List<CollectorInfo> ps = this.collectorInfoManager.getLatestCollectorInfo();
The JpaCollectorInfoManager.java has this:
public List<CollectorInfo> getLatestCollectorInfo()
{
return collectorInfoDao.getLatestCollectorInfo();
}
The JpaCollectorInfoDao.java:
@Override
@Transactional
public List<CollectorInfo> getLatestCollectorInfo() {
Query query = entityManager.createNativeQuery( ( "select distinct ON ( col.collector_id," +
"pst.process_source_type ) " +
"col.*," +
"pst.process_source_timestamp," +
"pst.process_source_type " +
"from perform_schema.collector col " +
"join perform_schema.process_set pst " +
"on pst.collector_id = col.collector_id " +
"order by col.collector_id, " +
"pst.process_source_type," +
"pst.process_source_timestamp desc " ),
CollectorInfo.class );
return ( (List<CollectorInfo>) query.getResultList() );
}
The CollectorInfo class does not have an @Entity defined. If I set the @Entity defined then it tells me that the Table cannot be resolved (which is correct since the there is no actual table). I have tried all sorts of permutations and cannot seem to make this needle thread.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定您到底想做什么?
您需要将类映射为实体,以便能够选择它的实例。
或者,不要包含该类,本机 SQL 查询将是数据的 Object[],您可以在自己的代码中将其映射到您的类。
或者将其映射为除您返回的数据之外的实体。当您将对象映射到查询结果时,@Table 将不相关。但这不会导致任何错误,除非您自动创建表或使用完整性检查器。
或者将对象正确映射到表。然后,如果需要,可以使用提取连接或批量提取来优化您的检索。
Not sure what you are trying to do exactly?
You need to map the class as an Entity in order to be able to select instances of it.
Either, do not include the class, the native SQL query will an Object[] of the data, which you can map in your own code to your class.
Or map it as an Entity excepting the data that you are returning. The @Table will not be relevant as you are mapping the object to the query results. This should not cause any errors though, unless you are auto creating table or using integrity checker.
Or map the objects to the table correctly. Then use a fetch join, or batch fetch to optimize your retrieval if required.