预期位置参数计数:1,实际参数:[]

时间:2013-01-23 21:53:08

标签: java hibernate

当我尝试使用来自DaoImpl类的HIbernate执行存储过程时,我得到以下异常。  我不确定是什么问题。我尝试了所有方法来解决它但没有解决问题。  任何人都可以帮助我,弄清楚代码或映射文件有什么问题。 我试图解决的越多,我得到的例外就越多......我正在连接到Oracle 9i DB。 我真的在2周内挣扎于此,没有任何地方......任何人都可以帮我解决这个问题。

映射文件:

<hibernate-mapping>

    <sql-query name="proc_drsrr_sel_ValDDSummaryBal">
    <!--CALL proc_drsrr_sel_ValDDSummaryBal(:param1)]]>-->
    { call DEFAULT_SCHEMA.proc_name(?,:param1) }

主类:

public static void main(String[] args) {
        String procName = "proc_name";// args[0];
        String params = "param1:500089" ;

DAO实施:

@SuppressWarnings("unchecked")
    public void callProc(String procName, Map paramMap) throws SQLException {
        Session session = null;
        Transaction tx = null;
        try {

            session = HibernateUtils.getSessionFactory().getCurrentSession();
            tx = session.beginTransaction();
            String dbURL = session.connection().getMetaData().getURL().toString();
            System.out.println("Conenction DB URL "+ dbURL );
            tx.setTimeout(5);
            String[] keys = new String[paramMap.size()];
            keys = (String[]) paramMap.keySet().toArray(keys);

            Query query = session.getNamedQuery(procName)
            .setParameter("param1", "5501010");

            }

            List result = query.list();
            System.out.println(query.getQueryString());
            for (int i = 0; i < result.size(); i++) {
                // logging the information.
                log.info(i);

            }
            tx.commit();
        } catch (RuntimeException exception) {
            exception.printStackTrace();
            try {
                tx.rollback();
            } catch (RuntimeException rbe) {
                log.error("Couldn’t roll back transaction", rbe);
                rbe.printStackTrace();
            }
            throw exception;
        } finally{   
                   if(session !=null){   
                      session.flush();      
                      session.close();      
            }

cfg.xml中

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@ldap://hdsoid.ute.ovi.com:3060/UT1DEV,cn=OracleContext,dc=ute,dc=ovi,dc=com</property>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.username">nameapp</property>
        <property name="connection.password">nameapp</property>
        <property name="connection.pool_size">1</property>   
        <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
       <!--   <property name="connection.release_mode">after_statement</property> -->
       <property name="default_schema">DEFAULT_SCHEMA</property>

        <property name="current_session_context_class">thread</property>
        <property name="hibernate.show_sql">true</property>
        <!-- mapping files -->
        <mapping resource="com/ovi/domain/hibernate.hbm.xml" />
    </session-factory>
</hibernate-configuration>

1 个答案:

答案 0 :(得分:8)

您缺少设置?参数,即所谓的positional parameter。与:foo

等命名参数形成对比

当你有一些SQL时,你还必须确保在评论中没有任何问号!这就是我刚遇到的。同样适用于评论中的:,特别是如果它们后跟空格。

相关问题