jpa调用只读合成表,但得到“异常描述:[CollectorInfo]的缺少描述符". [英] jpa call readonly composite table but getting "Exception Description: Missing descriptor for [CollectorInfo]"

查看:86
本文介绍了jpa调用只读合成表,但得到“异常描述:[CollectorInfo]的缺少描述符".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring 3应用程序中,控制器正在调用JpaCollectorManager,并调用JpaCollectorInfoDao以获取由nativequery定义的列表.该查询调用2个单独的表,这些表使用sql和jpql,因为我需要使用jpql中未实现的postgresql功能.当控制器尝试归档列表时,出现以下错误消息:

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:

异常[EclipseLink-6007](Eclipse持久性服务-2.1.2.v20101206-r8635):org.eclipse.persistence.exceptions.QueryException 异常描述:[CollectorInfo]的描述符缺失.
查询:ReadAllQuery(referenceClass = CollectorInfo sql ="select unique 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.按col.collector_id,pst.process_source_type,pst.process_source_timestamp desc)的collector_id顺序

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

控制器Java具有以下调用:

The controller Java has the following call:

List<CollectorInfo> ps = this.collectorInfoManager.getLatestCollectorInfo();

JpaCollectorInfoManager.java具有以下功能:

The JpaCollectorInfoManager.java has this:

public List<CollectorInfo> getLatestCollectorInfo()
{
  return collectorInfoDao.getLatestCollectorInfo();
}

JpaCollectorInfoDao.java:

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() );
  }

CollectorInfo类没有定义@Entity.如果我设置了@Entity定义,那么它将告诉我该表无法解析(由于没有实际的表,因此是正确的).我尝试了各种排列,似乎无法使该针线穿过.

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.

推荐答案

不确定要尝试执行的操作吗?

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.

或者,不包括该类,本机SQL查询将获取数据的Object [],您可以将其以自己的代码映射到您的类.

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.

或将其映射为实体(除了要返回的数据外).当您将对象映射到查询结果时,@ Table将不相关.除非您是自动创建表或使用完整性检查器,否则这不会引起任何错误.

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.

这篇关于jpa调用只读合成表,但得到“异常描述:[CollectorInfo]的缺少描述符".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆