Jpa call readonly composite table, but getting "Exception Description: Missing handle for [CollectorInfo]"

In a Spring 3 application, the controller calls JpaCollectorManager with calls to JpaCollectorInfoDao to get a list that is defined using the native query. The query calls two separate tables that use sql and jpql, because I need to use the postgresql function not implemented in jpql. When the controller tries to write a 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: A handle to [CollectorInfo] is missing.
Query: ReadAllQuery (referenceclass = CollectorInfo sql = "select different 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_setstcollectset colsetset.collectstset plect.setlect colsetstset. collector_id order by col.collector_id, pst.process_source_type, pst.process_source_timestamp desc ")

The Java controller has the following call:

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

JpaCollectorInfoManager.java has the following:

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

There is no @Entity value defined in the CollectorInfo class. If I set the @Entity value, then it will tell me that the table cannot be resolved (which is true since there is no actual table). I tried all kinds of permutations and it seems I canโ€™t make this needle thread.

+2
source share
1 answer

Not sure what you are trying to do for sure?

You need to map the class as Entity in order to be able to select its instances.

Or, do not include the class, your own SQL query will have a data object [], which you can map in your code in your class.

Or match it as an object, with the exception of the returned data. @Table will not matter as you map the object to the query results. This should not cause any errors unless you create an automatic table or use integrity checking.

Or, correctly map the objects to the table. Then use fetch combining or batch fetching to optimize your search if necessary.

+2
source

Source: https://habr.com/ru/post/1391149/


All Articles