1


Again, I'm puzzled... I'm sure there is a simple answer to my question.

I have implemented a UDF with MySQL i.e. to calculate median.
My question is; How do I "tell" Hibernate that MySQL contains the median-function, and not to return errors?

[IllegalStateException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode -[METHOD_CALL] MethodNode: '(' +-[METHOD_NAME] IdentNode: 'MEDIAN' {originalText=MEDIAN} -[EXPR_LIST] SqlNode: 'exprList' -[DOT] DotNode: 'elk0_.weight' {propertyName=weight,dereferenceType=PRIMITIVE,getPropertyPath=weight,path={synthetic-alias}.weight,tableAlias=elk0_,className=models.Elk,classAlias=null} +-[IDENT] IdentNode: '{synthetic-alias}' {originalText={synthetic-alias}} -[IDENT] IdentNode: 'weight' {originalText=weight} ]

elgbakken
  • 167
  • 1
  • 2
  • 10

1 Answers1

1

You will have to create a new class that contains your new function. This class will extend your current dialect, MYSQL5Dialect.

 public class CustomMySQLDialect extends MySQL5Dialect{
   public CustomMySQLDialect()
   {
          super();
          registerFunction("median", new StandardSQLFunction("median"));
   }
}

Now you have to tell hibernate to use your newly created dialect. I assume you have a XML file where you have configured hibernate.

 <property name="hibernate.dialect">com.hibernate.custom.dialect.CustomMySQLDialect</property>

For more information you can take a look at Keyur Joshi blog post

NoClueBlue
  • 451
  • 4
  • 17