Hibernate @formula is not supportinng Cast() as in

2019-01-20 17:48发布

I am using

@Formula("cast(item_code as \"int\")")

to cast a String column to int

but hibernate is generating the query as

and cast(this_.item_code as this_."int")=? 

How do i get rid of the alias in front of int ?

I tried :

@Formula("cast(item_code as "int")") and @Formula("cast(item_code as int)")

but still the same error . How do i cast the String to int ?

Thanks in advance .

1条回答
劳资没心,怎么记你
2楼-- · 2019-01-20 18:02

I have resolved an issue similar to yours. I extended the hibernate Dialect class for my database.

public class Oracle10gDialectExtended extends Oracle10gDialect {

    public Oracle10gDialectExtended() {
        super();
        /* types for cast: */
        registerKeyword("int");
        // add more reserved words as you need
    }
}

Set 'hibernate.dialect' property with this new class. Now your @Formula will work.

查看更多
登录 后发表回答