-->
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: Updating boolean values with MaxDB
PostPosted: Tue Jul 10, 2007 2:21 pm 
Newbie

Joined: Tue Jul 10, 2007 1:19 pm
Posts: 3
Hello!

The following code fragment works for MySQL, but does not for SAP-DB:

Code:
getExtHibernateTemplate().bulkUpdate("UPDATE AbstractOrder SET recent = false WHERE mainOrderId = :mainOrderId OR id = :mainOrderId", new String[]{"recent"}, new Object[]{false, order.getMainOrderId()});


The query Hibernate generates is:

Code:
update abstract_order set recent=0 where (id) IN (select id from temp.HT_abstract_order)


The MaxDB error is "Constant must be compatible with column type and length". The following query works (I tried it on the sqlcli console):

Code:
update abstract_order set recent=false where (id) IN (select id from temp.HT_abstract_order)


A workaround that works both with MySQL and MaxDB:

Code:
getExtHibernateTemplate().bulkUpdate("UPDATE AbstractOrder SET recent = :recent WHERE mainOrderId = :mainOrderId OR id = :mainOrderId", new String[]{"recent", "mainOrderId"}, new Object[]{false, order.getMainOrderId()});

This generates the following code:
Code:
update abstract_order set recent=? where (id) IN (select id from temp.HT_abstract_order)


Is there something I can do about this issue? (Passing a constant as a variable parameter doesn't seam too clever.) Can I change the way Hibernate converts the UPDATE HQL query to a SQL query? Is this a bug I should file in the JIRA?

Thanks for any help,
Matthias


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 3:06 pm 
Newbie

Joined: Tue Jul 10, 2007 1:19 pm
Posts: 3
Sorry to reply to my own post. It would be a good idea to have more patience... :-)

After a little bit digging around in HqlSqlWalker, I found the method processBoolean that calls a method of Dialect - toBooleanValueString(). This turned out to be exactly what I was looking for. The following small class solved my problems (that also occured with SELECT statements):

Code:
public class ExtSAPDBDialect extends SAPDBDialect {

   @Override
   public String toBooleanValueString(boolean bool) {
      return Boolean.toString(bool);
   }
   
}


Maybe it would be helpful to include this method in future versions of SAPDBDialect? (BTW, I'm using MAXDB 7.6).

Best regards,
Matthias


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.