-->
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.  [ 3 posts ] 
Author Message
 Post subject: Escaping String in Session.createSQLquery
PostPosted: Sat Jan 08, 2005 2:13 am 
Beginner
Beginner

Joined: Thu Dec 16, 2004 11:54 am
Posts: 26
Location: Brussels, Belgium
Hi,

[skip that intro if you wish]
I am currently using hibernate for the first time in a project, after seeing Gavin and Micheal speaking so dearly about it at Javapolis and JavaOne, I finally made the step, and I must say: GREAT! Thanks...
Still, I hae to get back to good ol' SQL for one particular job that builds a complex SQL query that I don't think could be made in HQL (special functions) and even if I could work I around that, I had no clue how to still do it in HQL and will leave that for later, when I've got more skills with Hibernate

[actual question]
Now the thing is as follows: I build up union'ed queries as one of the subqueries using an LIKE clause with words. Is there a way to escape these, as would be done using a preparedStatement?
Don't know if that's a Dialect dependent thing, but it would be one thing less to think about when migrating database (if that should ever happen, still the query would probably not run anymore as is anyway).
So is there a way to escape "Strings" on a SQL query using the Hibernate API?

Thanks for replying and thanks for Hibernate to the team (not useful, but I believe it's always nice to hear it),
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 08, 2005 9:59 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
If you're not going to use HQL then you can revert back to plain JDBC using session.connection(). Just use a PreparedStatement as per normal then - escaping strings using the ? character

If you are using HQL just use the named parameters (e.g. from a where a.name = :name)

Does this answer your question?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 08, 2005 3:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what do you mean with escaping as with preparedstatement ? That you can use ? or named parameters ? ...well, why don't you just do that ?

Either use createSQLQuery if your query return entities or just the good old session.connection() (which don't support named parameters of course)

_________________
Max
Don't forget to rate


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