-->
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: xxx is not mapped after using setParameter for native SQL
PostPosted: Wed Feb 18, 2009 5:17 am 
Newbie

Joined: Wed Feb 18, 2009 5:07 am
Posts: 8
What I am trying to do is to ask Hibernate to execute a native sql (not hsql) for me, like below.

select * from test where name = '123'

however, if I use setParameter as below:
Code:
String sql = "select * from test where name = ?";
SQLQuery query = getSession().createSQLQuery(sql);
query.setParameter(1, "123");


then exception occurs and complaint that:
table test is not mapped.

I understand that it's trying to find any java class mapped to test table, however, I just want it to be executed "exactly" as native sql like
Code:
String sql = "select * from test where name = '123'";
SQLQuery query = getSession().createSQLQuery(sql);


I just don't want to combine the parameter with the sql string and would like to let hibernate to set for me so that I don't need to encode any specific value according to the database.

Any people have idea how to achieve it?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 5:23 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Use in this way-
Code:
String sql = "select * from test where name = :name";
Query query = getSession().createSQLQuery(sql);
query.setParameter("name",123);
qyery.list();



Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 5:59 am 
Newbie

Joined: Wed Feb 18, 2009 5:07 am
Posts: 8
Your help is greatly appreciated.

Never thought that there is difference between these two ways and so never try this.

Shame on me.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 6:21 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
i will rally appreciate your rating for post.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.