我得到无效的列名错误,而使用JPA nativequery中的服务器。数据库是Oracle 10g
这是我的代码
Query query = em.createNativeQuery("select et.eqt_desc from ge_equip_type et",GeEquipType.class);
final List<String> equipList = query.getResultList();
下面是抛出的异常:
执行查询时发生SQLException,Map到select et.eqt_desc from ge_equip_type et [EXCEPTION]javax.ejb.EJBException:嵌套异常是:javax.persistence.PersistenceException:执行查询时发生SQLException,Map到select et.eqt_desc from ge_equip_type et
..................
..................
原因:java.sql.SQLException:在com.sap.engine.services.dbpool.wrappers. ResultSetWrapper.findColumn(ResultSetWrapper. java:87)处的oracle. jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3651)处的列名无效。jdbc.driver. OracleResultSetImpl.findColumn(OracleResultSetImpl. java:2543)
在com.sap.engine.services.orpersistence.query. getColumnNumber(getColumnFactory.java:239)
在com.sap.engine.services.orpersistence.core.PrimaryKey. python FrompersistentyResult(PrimaryKey.java:246)
在com.sap.engine.services.orpersistence.core.StoreManager. processing.txt(StoreManager.java:1631)
位于com.sap.engine.services.orpersistence.core.StoreManager.resultSet2ObjectList(StoreManager.java:1602)
在com.sap.engine.services.orpersistence.core.StoreManager. executeQueryWithoutProcessingEntityInfo(StoreManager.java:1120)在com.sap.engine.services.orpersistence.core.StoreManager.executeQuery(StoreManager.java:1141)在com.sap.engine.services.orpersistence.core.PersistenceContextImpl.executeQuery(PersistenceContextImpl. java:937)
GeEquipType类
package com.jnj.e2.cpl.orm;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table(name = "GE_EQUIP_TYPE")
@SequenceGenerator(name = "SEQ_EQT", sequenceName = "SEQ_EQT", allocationSize = 1, initialValue = 1)
@SuppressWarnings("serial")
public class GeEquipType implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_EQT")
@Column(name = "EQT_ID")
private Long uid;
@Column(name = "EQT_CODE")
private String code;
@Column(name = "EQT_DESC")
private String description;
@Column(name = "EQT_CLEAN_VAL_SPAN_DAYS")
private Long cleaningValiditySpan;
@Column(name = "EQT_INDC_PRODUCT_YN")
private String inDirectContactWithProduct;
@ManyToOne
@JoinColumn(name = "EQT_PRT_ID")
private GePrinterType printerType;
@Version
@Column(name = "EQT_OLV")
private Long version;
public Long getUid() {
return uid;
}
public void setUid(Long uid) {
this.uid = uid;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Long getCleaningValiditySpan() {
return cleaningValiditySpan;
}
public void setCleaningValiditySpan(Long cleaningValiditySpan) {
this.cleaningValiditySpan = cleaningValiditySpan;
}
public String getInDirectContactWithProduct() {
return inDirectContactWithProduct;
}
public void setInDirectContactWithProduct(String inDirectContactWithProduct) {
this.inDirectContactWithProduct = inDirectContactWithProduct;
}
public GePrinterType getPrinterType() {
return printerType;
}
public void setPrinterType(GePrinterType printerType) {
this.printerType = printerType;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
@Override
public int hashCode() {
return 31 + (uid == null ? 0 : uid.hashCode());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj == null || getClass() != obj.getClass()) {
return false;
}
final GeEquipType that = (GeEquipType) obj;
if (uid == null) {
if (that.uid != null) {
return false;
}
} else if (!uid.equals(that.uid)) {
return false;
}
return true;
}
}
注意:当我获取所有列或主键列,但不获取String列时,查询有效。
任何人请帮助。
2条答案
按热度按时间rqenqsqc1#
你能试着
此外,请确保在项目设置中有Oracle JDBC JAR文件。
vi4fp9gy2#
这个问题有几个解决方案1,您可以尝试@Transient到该表中的所有其他列。2、你可以尝试Hql,它可以返回object[],并在获取对象列表后将其转换为类。3、是使用criteria API获取查询。
1选项也是我有问题的地方,它可以使用本机查询,但不能使用hql。如果您编写代码中同时包含使用表的本机查询和HQL,那么我不知道该如何解决这个问题。