-->
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: SQL Function "passthrough" in HQL after migration
PostPosted: Fri Nov 18, 2005 10:54 pm 
Newbie

Joined: Fri Nov 18, 2005 6:31 pm
Posts: 4
Location: Indiana, USA
Hibernate version:
3.1 RC3

Dialect Used: org.hibernate.dialect.DB2390Dialect

I have upgraded an application from Hibernate 1.2.3 to 3.1. I have searched through the Hibernate forums for this issue, but can't find a solution. The following snippet was working in 1.2.x, but not in the upgrade. Basically, I need to allow the month function to "pass through" the HQL. I found reference to calling sql functions in "Hibernate In Action" book, but this only seems to be specific to Hibernate 2, and the HQL parser failes

HQL snippet:
Code:
from com.mycompany.Message msg WHERE msg.incomingMessageMonth = MONTH(current timestamp - 1 month)


Any help would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 19, 2005 1:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Create a custom dialect that registers an SQLFunction.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 19, 2005 2:48 pm 
Newbie

Joined: Fri Nov 18, 2005 6:31 pm
Posts: 4
Location: Indiana, USA
Thanks for the reply. I have created a custom dialect which extends the Dialect I'm using. It registers the NoArgSQLFunction, specifiying the name of the function. For a test, I wanted to see if the HQL parser would "ignore" the test SQL function "my_month_func"; however, it is still trying to parse it. I'd expect it to fail on the database end.

I'm making an assumption I don't have to create a custom SQLFunction?

Code:
package test;

import org.hibernate.Hibernate;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.function.NoArgSQLFunction;
import org.hibernate.dialect.function.SQLFunction;

public class CustomlDialect extends DB2390Dialect {
   
   public CustomlDialect() {
      SQLFunction sqlFunction = new NoArgSQLFunction("my_month_func",Hibernate.INTEGER, true);
      registerFunction("my_month_func", sqlFunction);
      System.out.println("Registered sql function: "+sqlFunction.getClass());
   }

}


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.