-->
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: is % (percentage) a special charecter ?
PostPosted: Mon Apr 19, 2004 7:12 am 
Newbie

Joined: Mon Apr 05, 2004 3:14 am
Posts: 13
hi,

i am trying to execute a native sql thru Hibernate.

select max(CAST(substring(p1.fld1,9,25) as int)) as {p1.fld1}
from table1 {p1} where p1.fld1 like :cat_id

the cat id is : 'partcat%'

( from a string field , get a integer , then find its max, so i can create primary key. ie. emp-1, emp-2 etc.. )

if i removed the percentage the sql works ok, via Hibernate.

if i placed the percentage sign (important for me) , then Hibernate gives error saying :

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid column name: part_cat2_0_

Hibernate seems to think that there is an extra column ?

this error does not occur everytime, but once in 2 attempts at the sql.

the generated sql is :
select max(CAST(substring(p1.part_category_id,9,25) as int)) as part_category_id0_
from part_category_master p1 where p1.part_category_id like ?

any tips are welcome.

thanks in advance.

iyyappan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 7:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
do you use setString to set the parameter value?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 19, 2004 7:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
BTW, remember can only return hibernate mapped classes, not scalar values.


Top
 Profile  
 
 Post subject: code fragment
PostPosted: Mon Apr 19, 2004 7:19 am 
Newbie

Joined: Mon Apr 05, 2004 3:14 am
Posts: 13
my java is :

List list = session.getNamedQuery("table1.test").setString("cat","emp%").list();

and the sql is :

<sql-query name="table.test">
<return alias="p1" class="abc.emp"/><![CDATA[
select max(CAST(substring(p1.emp,9,25) as int)) as {p1.emp_id}
from employees {p1} where p1.emp_id like :cat ]]>
</sql-query>


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.