在带有Oracle 10g数据库的netweaver服务器中使用JPA nativequery时出现无效的列名错误

时间:2016-09-20 07:17:57

标签: oracle jpa jpql nativequery netweaver

我在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,映射到ge_equip_type et中选择et.eqt_desc       [EXCEPTION] javax.ejb.EJBException:嵌套异常是:javax.persistence.PersistenceException:执行查询时发生SQLException,映射到从ge_equip_type等中选择et.eqt_desc ............ ......
  ..................
      引起:java.sql.SQLException:列名无效       at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3651)       at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:2543)       at com.sap.engine.services.dbpool.wrappers.ResultSetWrapper.findColumn(ResultSetWrapper.java:87)
      at 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)
      at com.sap.engine.services.orpersistence.core.StoreManager.resultSet2ObjectList(StoreManager.java:1602)
      at 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;
  }
}

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

任何人都请帮忙。

1 个答案:

答案 0 :(得分: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文件。