java 预期位置参数个数:1,实际参数:[]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14490111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Expected positional parameter count: 1, actual parameters: []
提问by user2005493
I am getting this below exception when I am trying to execute a Stored procedure using HIbernate from DaoImpl Class. I am not sure of what is wrong ..I tried all the ways to fix it but did not resolve the issue. Could anyone please help me ,figure out whats wrong with the code or the mapping file. The more I am trying to fix ,something the more exceptions I am getting.. I am connectuing to Oracle 9i DB. I am struggling on this from really 2 weeks ending up no where.. can anyone please help me fix this issue.
当我尝试使用 DaoImpl 类中的 HIbernate 执行存储过程时,出现以下异常。我不确定出了什么问题..我尝试了所有方法来解决它,但没有解决问题。任何人都可以帮助我,找出代码或映射文件有什么问题。我尝试修复的越多,我得到的异常就越多..我正在连接到 Oracle 9i DB。从真正的 2 周开始,我一直在为此苦苦挣扎,最终无处可去.. 任何人都可以帮我解决这个问题。
Mapping file:
映射文件:
<hibernate-mapping>
<sql-query name="proc_drsrr_sel_ValDDSummaryBal">
<!--CALL proc_drsrr_sel_ValDDSummaryBal(:param1)]]>-->
{ call DEFAULT_SCHEMA.proc_name(?,:param1) }
Main-Class:
主类:
public static void main(String[] args) {
String procName = "proc_name";// args[0];
String params = "param1:500089" ;
DAO Implementation:
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>
回答by Tarion
You are missing to set the ?
parameter which is a so called positional parameter
. In contrast to named parameters like :foo
您缺少设置?
所谓的参数positional parameter
。与命名参数相反:foo
When you have some SQL you must also ensure not to have any Question Marks inside comments! That's what I just ran into. Same holds for :
in comments, especially if they are followed by a space.
当您有一些 SQL 时,您还必须确保注释中没有任何问号!这就是我刚刚遇到的。同样适用:
于评论,特别是如果它们后面跟着一个空格。