我收到错误“列名无效”

时间:2011-11-01 08:47:55

标签: java oracle hibernate stored-procedures

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.vijay.Transfee" table="TRXN_FEE_TABLE">
<meta attribute="class-description">
This class contains the course details.
</meta>
<id name="Tcode" type="string" column="TRXN_FEE_CODE" >
    </id>
<property name="Icode" type="string" column ="INSTCODE" />
<property name="Pcode" type="string" column ="PRODUCT_CODE" />
<property name="Tcode1" type="string" column ="TRANSACTION_CODE" />
<property name="rebate_code1" type="string" column="REBATE_CODE"/>
</class>
<sql-query name="F_SP" callable="true">
    <return alias="fee"  class="com.vijay.Transfee">
        <return-property name="rebate_code1" column="REBATE_CODE"/>
    </return>
    { call Feeproc1(?) }
 </sql-query>
</hibernate-mapping>

package com.vijay;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import java.util.*;

public class A {

    public static void main(String[] args){

        Configuration config = new Configuration();
        SessionFactory factory = config.configure().buildSessionFactory();
        System.out.println(">>>>>>>>1");
        Session session = factory.openSession();
        Transaction tx = session.beginTransaction();
        Query query = (Query)session.getNamedQuery("F_SP"); 
        System.out.println(">>>>>>>>2");
        List result = query.list();
        System.out.println(query.list());
        Iterator it=result.iterator();
        while(it.hasNext())
        {
            Object[] sublist1 = (Object[])it.next();
            System.out.println(">>>>>>>>3");
            String Trx = (String)sublist1[0];
            System.out.println(">>>>>>>>4");
            System.out.println(Trx);
        }
        System.out.println(">>>>>>>>5");
        System.out.println(result);
}
}

我正在调用存储过程并打印我调用的那个,但它显示以下错误

    
    Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
        at org.hibernate.loader.Loader.doList(Loader.java:2536)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
        at org.hibernate.loader.Loader.list(Loader.java:2271)
        at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
        at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
        at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
        at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
        at com.vijay.A.main(A.java:24)
    Caused by: java.sql.SQLException: Invalid column name
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:147)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:209)
        at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3325)
        at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1926)
        at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1515)
        at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$2.doExtract(VarcharTypeDescriptor.java:61)
        at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
        at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:254)
        at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:250)
        at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:230)
        at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:331)
        at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:668)
        at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
        at org.hibernate.loader.Loader.doQuery(Loader.java:829)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
        at org.hibernate.loader.Loader.doList(Loader.java:2533)
        ... 7 more
CREATE OR REPLACE PROCEDURE LYCAMONEY.Feeproc1(p_cursor  OUT  sys_refcursor)
as rebate_code1 varchar2(20);
begin

  rebate_code1 := null;
  open p_cursor for
    select REBATE_CODE into rebate_code1  from TRXN_FEE_TABLE;

 dbms_output.put_line(rebate_code1 );

end;
/

任何人都可以帮我解决这个问题......如果

,也可以发布正确的方法

1 个答案:

答案 0 :(得分:1)

嗯,您的存储过程对于初学者来说是错误的。它应该是:

open p_cursor for
    select REBATE_CODE from TRXN_FEE_TABLE;

这是错误的,因为引用游标是指向查询的指针。它实际上并没有获取任何数据。

但我认为这不是给你错误的原因。