-->
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.  [ 2 posts ] 
Author Message
 Post subject: use_sql_comments error
PostPosted: Sun Oct 07, 2007 7:52 am 
Beginner
Beginner

Joined: Sat Oct 09, 2004 2:35 pm
Posts: 43
Location: Tenerife
Hibernate version:
3.2.5

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
12:06:51,641 INFO org.hibernate.type.StringType[1]:144 - could not bind value '' to parameter: 2; Invalid column index.

Name and version of the database you are using:
firebird 2.0.3

The generated SQL (show_sql=true):
/* FindFirstRow */ /* cri first ?teria query */ select
this_.ID as ID1_0_,
this_.CODE as CODE1_0_,
this_.NAME as NAME1_0_
from
ROLE this_
where
this_.CODE>=?
order by
this_.CODE asc

IT SHOULD BE:
/* FindFirstRow */ /* criteria query */ select
this_.ID as ID1_0_,
this_.CODE as CODE1_0_,
this_.NAME as NAME1_0_
from
ROLE this_
where
this_.CODE>=?
order by
this_.CODE asc

Debug level Hibernate log excerpt:


----
This error only happens when I use
Code:
use_sql_comments = true
.
I use a criteria query with setMaxResults(1).
Observe "first ?" inside comment generated
As I set use_sql_comments to false, everithing works again as expected.
If I suppress setMaxResults(1) the query works also as such a query.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 10, 2007 6:56 pm 
Beginner
Beginner

Joined: Sat Oct 09, 2004 2:35 pm
Posts: 43
Location: Tenerife
Well, I've been looking around the code for a while and found the solution in adding a little modification to org/hibernate/dialect/FirebirdDialect.java
Code:
   public String getLimitString(String sql, boolean hasOffset) {
      return new StringBuffer( sql.length()+20 )
         .append(sql)
         .insert(6, hasOffset ? " first ? skip ?" : " first ?")
         .toString();
   }


to look like this:
Code:
   public String getLimitString(String sql, boolean hasOffset) {
      return new StringBuffer( sql.length()+20 )
         .append(sql)
         .insert(sql.toLowerCase().indexOf( "select" ) + 6, hasOffset ? " first ? skip ?" : " first ?")
         .toString();
   }

It was already working on HSQLDialect, actually.

Hope this change will appear in next release cause comments are a really interesting thing in order to debug a program.


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