These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate HQL Named Parameter Exception
PostPosted: Wed Feb 22, 2006 2:44 am 
Newbie

Joined: Wed Feb 22, 2006 2:29 am
Posts: 5
Hi,
I am using Hibernale version 3.1.2.
The mapping file used in my appln is as folows.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

<session-factory>
<property name="myeclipse.connection.profile">testhibernate</property>
<property name="connection.url">jdbc:odbc:OMX</property>
<property name="connection.username">sa</property>
<property name="connection.password">sa</property>
<property name="connection.driver_class">sun.jdbc.odbc.JdbcOdbcDriver</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<mapping resource="ClientTable.hbm.xml" />

</session-factory>

</hibernate-configuration>

I am using SQL 2000 DB.

The config file used is as follows:
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>

<class name="ClientTable" table="client_table">
<id name="clientId" column="client_id" type="java.lang.Long">
</id>

<property name="clientName" column="client_name" type="java.lang.String" not-null="true" />
<property name="clientLocation" column="client_location" type="java.lang.String" not-null="true" />
<property name="clientEmail" column="client_email" type="java.lang.String" not-null="true" />
</class>

</hibernate-mapping>


I am tryig to run a select Query on the table. However i get the following Exception..........
java.lang.IllegalArgumentException: Parameter name does not exist as a named parameter in [FROM ClientTableas ct WHERE ct.client_name = :client_name]
at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:380)
at org.hibernate.impl.AbstractQueryImpl.setString(AbstractQueryImpl.java:399)
at AMDClient.main(AMDClient.java:29)

My Code my is as follows.........
import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class AMDClient
{
public static void main(String[] args)
{
// open session
Session session = HibernateSessionFactory.currentSession();

Query qry = session.createQuery("FROM "+ClientTable.class.getName()+"as ct WHERE ct.client_name = :client_name");
qry.setString("client_name", "Kapil Dingore");

List list = qry.list();

if (list.size() == 0)
{
System.out.println("No records found");
System.exit(0);
}
else
{
for (int i = 0; i< list.size(); i++)
{
String str = (String) list.get(i);
System.out.println("result-----"+i+"------"+ str);
}
}
session.close();

}
}

Can any one please help........... i have been trying this for quiet sometime....but in vain :(

_________________
- 5thElement


Top
 Profile  
 
 Post subject: Solution
PostPosted: Wed Feb 22, 2006 3:05 am 
Newbie

Joined: Wed Feb 22, 2006 2:15 am
Posts: 10
Do not use client_name as parameter name since it is same as the method name use different name.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 3:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
are you completely sure you actual call setParameter("client_name",...) and not setParameter("name",...) ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 5:54 pm 
Beginner
Beginner

Joined: Sun Oct 16, 2005 12:37 pm
Posts: 47
Location: Romania, Galati
I think hibernate query must look like:

Query qry = session.createQuery("FROM "+ClientTable.class.getName()+" as ct WHERE ct.clientName = :client_name");

not like

Query qry = session.createQuery("FROM "+ClientTable.class.getName()+"as ct WHERE ct.client_name = :client_name");

'cose property name is clientName not client_name. And a space before as...

I hope this solve :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.