gpt4 book ai didi

java - EclipseLink 在从 createNativeQuery 获取结果集之前随机触发查找查询

转载 作者:太空宇宙 更新时间:2023-11-04 12:24:15 25 4
gpt4 key购买 nike

EclipseLink 的奇怪行为(Eclipse Persistence Services - 2.1.1.v20100817-r8050),我有一个 false(虚拟/不是数据库中的实际表)实体类来保存从 createNativeQuery(query,entity.class) 返回的结果集 @实体 公共(public)类 VirtualTable 实现可序列化 { 私有(private)静态最终长serialVersionUID = 1L;

@Id
@Column(name = "ROW")
private Integer row;

@Column(name = "ABC")
private String abc= null

@Column(name = "XYZ")
private String xyz= null

下面是我获取结果集的代码我已将entityClass 设置为VirtualTable.class

/**
* Get a list of entity objects by a native query.
*
* @param nativeQueryString the query.
* @param qryParamList the parameters for the query. Must be in the same order as listed in the query.
* @param entityClass the Class of the entity object. The entityClass field must be mapped to the
* column names from the query result set.
* @return a list of entity object of class entityClass
*/
@SuppressWarnings("rawtypes")
public static List getObjectListByNativeQuery(String nativeQueryString,
List<Object> qryParamList, Class entityClass) {
EntityManager em = ReportRepository.getEntityManager(SqlConstants.PERSISTENCE_UNIT_NAME_PODR_RPT );

//populate the parameter list
logger.info("em test inside query"+ em.hashCode() +" "+nativeQueryString + ", with ref class: " + entityClass.getName());
Query query = em.createNativeQuery(nativeQueryString, entityClass);

if(qryParamList != null && qryParamList.size() > 0) {
for(int i=0; i< qryParamList.size(); i++) {
Object param = qryParamList.get(i);
//the native query parameters must start with 1
query.setParameter(i+1, param);
}
}
List resultList = query.getResultList();
return resultList;
}enter code here

在返回结果集之前,JPA 尝试自行触发查找查询,并且由于该表不在数据库中,因此它会抛出表未找到的错误。我在 persistence.xml 中使用 SOFT 缓存,而不是它是一个简单的 JPA 实现。请让我知道如何避免 JPA 对此特定实体类进行查询并定义它不是实际的数据库表。我想避免手动映射,我不会在任何地方保留这个虚拟表,只是获取结果集并写入 Excelsheet

错误日志如下

  [7/21/16 2:46:43:455 EDT] 0007f794 SystemOut     O 2016-07-21   02:46:43.455 [WARN]     org.eclipse.persistence.session.podr02_user=PODRRPT.internalLog:588@PODRSchedWorkManager.Alarm Pool : 12  -  Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

Error Code: 942
Call: SELECT ROW, ABC, XYZ FROM VIRTUALTABLE WHERE (ROW = ?)
bind => [79]
Query: ReadObjectQuery(referenceClass=VirtualTable )

[7/21/16 2:46:43:455 EDT] 0007f794 SystemOut O 2016-07-21 02:46:43.455 [ERROR] com.bmo.cm.common.framework.service.AbstReportFileGenerator.generateReportFil e:88@PODRSchedWorkManager.Alarm Pool : 12 - Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

Error Code: 942
Call: SELECT ROW, ABC, XYZ FROM VIRTUALTABLE WHERE (ROW = ?)
bind => [79]
Query: ReadObjectQuery(referenceClass=VirtualTable )

最佳答案

您不应该为此使用实体,因为实体需要 JPA 来管理和跟踪它们的更改,需要对象标识和缓存。相反,如果使用 JPA 2.1,您应该使用构造函数表达式来使用 ConstructorResult 构建 pojo在SqlResultSetMapping

关于java - EclipseLink 在从 createNativeQuery 获取结果集之前随机触发查找查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38529607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com