I am using
@Formula(\"cast(item_code as \\\"int\\\")\")
to cast a String
column to int
but hiberna
Try:
@Formula("cast(item_code as NUMERIC(1,0))")
The problem is that the dialect you are using does not recognize int
as a Type (see org.hibernate.dialect.isTypeNameRegistered()).
You can either use the exact type based on your dialect (e.g. PostgreSQL uses int4
but DB2, Ingres and H2 uses integer
...) or you can use NUMERIC(1,0)
because everything what is followed by parentheses is considered to by a Function or a Keyword (see org.hibernate.sql.Template.isFunctionOrKeyword()).
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.