-->
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.  [ 8 posts ] 
Author Message
 Post subject: Native SQL Querys!!! Help
PostPosted: Tue Jun 14, 2005 7:18 am 
Hi everybody!

We are getting in trouble with the native sql queries. We need to load data from a not mapped table into an object of a mapped class.

Something like:

table ZipData (zip string , city string )

into an object of:

class Address {
string zipcode;
string city;
}

we are trying this code:

String sql ="select zc.city as addr.City, zc.code as addr.ZipCode, " +
"from ZipCodes zc where addr.code = :zipCode";

session.CreateSQLQuery(sql, "addr", typeof(Address))
.SetString("zipCode", zipCode)
.List();

but it throws a nasty Exception: incorrect sintax near "."

Any suggestions will be very welcome ;-)

thks!

jv


Top
  
 
 Post subject: Re: Native SQL Querys!!! Help
PostPosted: Wed Jun 15, 2005 4:24 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
String sql ="select zc.city as addr.City, zc.code as addr.ZipCode, " +
"from ZipCodes zc where addr.code = :zipCode";

addr.City, addr.ZipCode, addr.code are all wrong.
Try :

String sql ="select zc.city as City, zc.code as ZipCode, " +
"from ZipCodes zc where code = :zipCode";


Radu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 9:13 am 
Thanks for your answer...but this solution give us another error

String sql ="select zc.city as City, zc.code as ZipCode, " +
"from ZipCodes zc where code = :zipCode";

IList addresses = session.CreateSQLQuery(sql, String.Empty,
typeof (Address)).
.SetString(zipCode, "08820")
.List();

Error:
IndexOutOfRangeException: id0_

Someone can help us?


Top
  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 2:05 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This should work in the CVS version, 0.8.4 doesn't really support SQL queries, since some relevant code wasn't ported yet when it was released.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 11:55 am 
Newbie

Joined: Tue Jun 14, 2005 9:23 am
Posts: 9
I have the same error...(((

this code works:
SELECT {price.*}
FROM vw_minprice {price}
WHERE price.id_goods in
(
SELECT id_goods
FROM tb_favorites_list_item
WHERE id_favorites_list=:idFavoritesList
)


but I need get a count of objects, but I don't now how to make this... All my attempts add count() function failed


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 3:23 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Why don't you just use a plain SQL query (IDbCommand)? You can obtain a connection from the session and use it to run queries. SQL queries are useful if you want to represent the results of your query as persistent objects.


Top
 Profile  
 
 Post subject: Supported Yet?
PostPosted: Mon Aug 15, 2005 2:31 pm 
Regular
Regular

Joined: Tue May 24, 2005 12:55 pm
Posts: 56
Are native SQL queries now supported in 0.9? (per Hibernate 2.1.7 docs) I didn't see anything in the release notes. If not, does this need to be posted in JIRA?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 15, 2005 4:05 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, they should be working fully now. If you find something that does not work, report it as a bug.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.