-->
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.  [ 7 posts ] 
Author Message
 Post subject: Raw sql in Hibernate 2.0.3
PostPosted: Fri Oct 17, 2003 4:10 pm 
Beginner
Beginner

Joined: Wed Sep 17, 2003 10:25 am
Posts: 36
Is there a way to sent raw sql in Hibernate 2.0.3? I have read about createSQLQuery around the forum but did not find any similarly clean way to do this in 2.0.3.

BTW, upgrade to 2.1 will not work for me :)..

Thanks...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2003 4:11 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can only use session.connection().... in Hibernate 2.0.x.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2003 4:13 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Get the underlying SQL connection
Code:
Connection conn = session.connection();

And execute SQL code.
caution No object mapping is done this way.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Thanks..
PostPosted: Fri Oct 17, 2003 4:18 pm 
Beginner
Beginner

Joined: Wed Sep 17, 2003 10:25 am
Posts: 36
Thanks christian. Guess will have to go that route? But here is another question, I am trying to send a query to the database (MSSQL Server) and I want to add a string to my query. Say I have the following query:

Select * from myTable where name like '%na%'

I want to send this down to the database as the following:

Select * from myTable where name like N'%na%'

This is required as I want to send UTF characters/strings to the database. I tried adding it to the query I use in session.find but that is not really doing it for me. I keep getting that the syntax is incorrect. What ways are available to me to customize the sql that is being passed to the database (especially my where clause).


Top
 Profile  
 
 Post subject: One more thing
PostPosted: Fri Oct 17, 2003 5:35 pm 
Beginner
Beginner

Joined: Wed Sep 17, 2003 10:25 am
Posts: 36
When I send my query, for example,
Select count(*) from myClass as m where m.name like N'%na%'

It hits the database as the following:
Select count(*) from myTable as m where m.name like N '%na%'

It creates a space between N and '%na%'. Is this normal? This is causing the query to not execute due to syntax problems??


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 18, 2003 9:30 am 
Regular
Regular

Joined: Tue Aug 26, 2003 3:09 pm
Posts: 58
Are you sure your driver isn't doing this for you? I'm using jTDS and it appears to take care of that for me automatically. Not sure if other drivers do it. You can use SQL Server Profiler to check.

Joe


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 19, 2003 7:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
HIbernate does not support a N'foo' style string literal. So just use a query parameter instead of a literal and let the JDBC driver take care of it.


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