Troncador
Troncador

Reputation: 3556

How can the criteria api add quote to the column?

In my aplication I use eclipselink and the criteria api.

My database have a table with a column called "order".

The problem is when I use the criteria api to create a select it made this sql:

SELECT id, order, name, phone, uri FROM campus

It throw a exception because "order" is a restrict keyword in sql

How can I force the criteria api to put quotes in the columns names?

Upvotes: 0

Views: 320

Answers (2)

Chris
Chris

Reputation: 21165

Renaming the field is an easier option, but JPA will quote delimited fields. To mark it as delimited, just add quotes when defining the column: "\"order\"".

Upvotes: 0

AlexR
AlexR

Reputation: 115378

The easiest (and IMHO the best) way is to change order to campus_order or something like that and avoid using SQL keywords as a field identifier. This practice typically causes problems.

I will be glad to know that criteria API has some kind of work around for this problem but I'd recommend you to rename the column. Today you are using criteria API, tomorrow you will use something else... But at the end of the day the good old SQL is generated and the last think you want is to find that one of your queries does not work because the column name equals to keyword of one of SQL versions.

Upvotes: 1

Related Questions