1

在 netweaver 服务器中使用 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 发生执行查询,映射到 select et.eqt_desc from ge_equip_type et [EXCEPTION]javax.ejb.EJBException: 嵌套异常是:javax.persistence.PersistenceException: SQLException 发生执行查询,映射到 select et.eqt_desc from ge_equip_type et
。 .................................................. 原因:java.sql.SQLException:oracle 中的列名无效

jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3651) 在 oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:2543) 在 com.sap.engine.services.dbpool.wrappers.ResultSetWrapper.findColumn(ResultSetWrapper.爪哇:87)
在 com.sap.engine.services.orpersistence.query.EntityResultFactory$NamedEntityResult.getColumnNumber(EntityResultFactory.java:239)
在 com.sap.engine.services.orpersistence.core.PrimaryKey.createFromEntityResult(PrimaryKey.java:246)
在 com .sap.engine.services.orpersistence.core.StoreManager.processEntityRow(StoreManager.java:1631)
在 com.sap.engine.services.orpersistence.core.StoreManager.resultSet2ObjectList(StoreManager.java:1602)
在 com.sap.engine.services.orpersistence.core.StoreManager.executeQueryWithoutProcessingEntityInfos(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;
  }
}

注意:当我获取所有列或主键列但不是字符串列时,查询有效。

任何人请帮忙。

4

1 回答 1

0

你可以试试

String sql = "select et.eqt_desc from  ge_equip_type et";
Query query = em.createNativeQuery(sql, GeEquipType.class);
List<GeEquipType> equipList = (List<GeEquipType>) query.getResultList();

此外,请确保您的项目设置中有 Oracle JDBC JAR 文件。

于 2016-09-20T11:52:21.217 回答