Dutij
Dutij

Reputation: 11

How can i use TO_CHAR method in hibernate Criteria

I am using Hibernate Criteria to get all rows from a table.

I want a specific row gets formatted like 24,555.00.

SQL query to get something like this

select TO_CHAR(TOTAL_AMT_TRNS, '999,999,999,999.00') 
from deductions 

I want same TO_CHAR method in Criteria to get formatted column.

Upvotes: 0

Views: 1650

Answers (1)

SergeiBednar
SergeiBednar

Reputation: 390

I don't believe you can really inject that into a criteria query, unless you've mapped this field in the entity you're querying.

You can achieve what you're trying to do with a @Formula

@Formula is basically a new field in an entity, but not necessarily mapped to a column in the DB, in your case the mapping will look something like this:

@Formula("TO_CHAR(totalAmtTrans, '999,999,999,999.00')") // Note that you're referring to other fields' names and not the column names while writing a criteria, although it's regular SQL in every other regard
private String totalAmtTransFormatted;

Upvotes: 2

Related Questions