-->
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: Custom SQLFunction not being called under Hibernate 3.0.2
PostPosted: Fri May 13, 2005 5:42 pm 
Newbie

Joined: Mon Apr 18, 2005 4:47 pm
Posts: 4
Location: Rugby, UK
I have a problem with a custom SQLFunction and MySQLDialect which has only started happening since switching from Hibernate 3.0 to Hibernate 3.0.2 and 3.0.3.

I have written a MySQLBitwiseAndSQLFunction class derived from StandardSQLFunction which implements the bitwise AND functionality for the MySQLDialect which used to work in Hibernate 2 but was dropped from Hibernate 3.

Hibernate version:
3.0.2 and 3.0.3

Mapping documents:
Not relevent

Code between sessionFactory.openSession() and session.close():
My SQLFunction class looks like the following:

Code:
public class MySQLBitwiseAndSQLFunction extends StandardSQLFunction {

  public MySQLBitwiseAndSQLFunction(String name) {
    super(name);

  }

  public MySQLBitwiseAndSQLFunction(String name, Type typeValue) {
    super(name, typeValue);
  }

  public String render(List args) {

    if (args.size() != 2) {
      throw new IllegalArgumentException("MySQLBitwiseAndSQLFunction requires 2 arguments!");
    }
    StringBuffer buffer = new StringBuffer(args.get(0).toString());
    buffer.append(" & ").append(args.get(1));
    return buffer.toString();
  }
 
}


and my MySQLDialect class looks like this:

Code:
public class MySQLDialect extends org.hibernate.dialect.MySQLDialect {

  public MySQLDialect() {
    super();
    logger.info("Creating MySQLDialect instance");
    registerFunction("bitwise_and", new MySQLBitwiseAndSQLFunction("bitwise_and", Hibernate.INTEGER));
  }
}

My application is configured to use this custom dialect using the hibernate.dialect property.

Full stack trace of any exception that occurs:
Not applicable

Name and version of the database you are using:
RDBMS: MySQL, version: 4.0.12-nt
JDBC driver: MySQL-AB JDBC Driver, version: 3.0.7-stable ( $Date: 2003/04/08 18:29:14 $, $Revision: 1.27.2.16 $ )

The generated SQL (show_sql=true):
See below

Debug level Hibernate log excerpt:
See below


Under Hibernate 3.0 my custom SQLFunction works entirely as expected - "bitwise_and(X,Y)" references in HQL queries gets mapped to "X & Y". However, under Hibernate 3.0.2 and 3.0.3 (sorry, haven't tried 3.0.1) I get exceptions when executing the SQL because the expected bitwise_and function translation has not taken place.

Looking at log output, under Hibernate 3.0 you can see that my custom SQLFunction class is called and the expected HQL -> SQL translation occurs:

Code:
2005-05-12 18:31:09,992 [Request Handler 1] [DEBUG] [2] [org.hibernate.hql.ast.ErrorCounter] > throwQueryException() : no errors
2005-05-12 18:31:10,002 [Request Handler 1] [INFO ] [2] [com.purplegem.persist.MySQLBitwiseAndSQLFunction] > Rendering bitwise_and function to SQL
2005-05-12 18:31:10,002 [Request Handler 1] [DEBUG] [2] [org.hibernate.hql.ast.QueryTranslatorImpl] > HQL: select count(*) from com.purplegem.domain.supplier.Supplier supplier where supplier.shortName like :shortName and supplier.address.town like :town and supplier.address.postcode like :postcode and bitwise_and(supplier.bitMask, :bitMask) > 0 order by supplier.shortName
2005-05-12 18:31:10,002 [Request Handler 1] [DEBUG] [2] [org.hibernate.hql.ast.QueryTranslatorImpl] > SQL: select count(*) as col_0_0_ from pg_supplier supplier0_ where ((supplier0_.ShortName like ?) and (supplier0_.Town like ?) and (supplier0_.Postcode like ?) and supplier0_.bitMask & ?>0) order by  supplier0_.ShortName

However, under Hibernate 3.0.3 my SQLFunction is never called with the result that the HQL -> SQL translation does not occur:

Code:
2005-05-12 18:59:46,030 [Request Handler 1] [DEBUG] [2] [org.hibernate.hql.ast.ErrorCounter] > throwQueryException() : no errors
2005-05-12 18:59:46,040 [Request Handler 1] [DEBUG] [2] [org.hibernate.hql.ast.QueryTranslatorImpl] > HQL: select count(*) from com.purplegem.domain.supplier.Supplier supplier where supplier.shortName like :shortName and supplier.address.town like :town and supplier.address.postcode like :postcode and bitwise_and(supplier.bitMask, :bitMask) > 0 order by supplier.shortName
2005-05-12 18:59:46,040 [Request Handler 1] [DEBUG] [2] [org.hibernate.hql.ast.QueryTranslatorImpl] > SQL: select count(*) as col_0_0_ from pg_supplier supplier0_ where (supplier0_.ShortName like ?) and (supplier0_.Town like ?) and (supplier0_.Postcode like ?) and bitwise_and(supplier0_.bitMask, ?)>0 order by supplier0_.ShortName
2005-05-12 18:59:46,040 [Request Handler 1] [DEBUG] [2] [org.hibernate.hql.ast.ErrorCounter] > throwQueryException() : no errors


So, it looks like my custom SQLFunction is just not being applied.

Given that the only difference between it working and not working is a different version of Hibernate, could this be a bug that has been introduced to Hibernate or am I doing something wrong?

Regards,

Darren Scott


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 14, 2005 1:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Please submit a really trivial, runnable test case to JIRA. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 1:01 pm 
Newbie

Joined: Mon Apr 18, 2005 4:47 pm
Posts: 4
Location: Rugby, UK
Gavin,

I've raised a JIRA issue (HHH-489) with requested test case attached.

Thanks,

Darren


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.