Add support to opt columnDefinitions out of globally-quoted-identifiers

Description

I'm developing a project using spring boot and hibernate as a JPA provider for MySql.

Since I've some problems defining unique indexes due to reserved words I set the property hibernate.globally_quoted_identifiers to true.

This solves that problem but creates another when using columnDefinitions because hibernate put quotes on them too.

For example if I add columnDefinition="blob" then hibernate tries to execute this DDL:

i.e.: it puts "`" around the "blob" keyword, while it should not.

Activity

Show:

Steve Ebersole January 9, 2016 at 6:47 PM

Look... You reported that if you "set the property hibernate.globally_quoted_identifiers to true" that Hibernate "puts "`" around the "blob" keyword, while it should not". That is your report here.

I pointed out that, in fact, Hibernate should quote (put "`" around) blob, not because it is a keyword but because you asked Hibernate to quote all identifiers and JPA says that columnDefinition falls into this category. I pointed all this out to you even including the spec sections and quoting the important snippets. You are the one who keeps confusing why that happens - it has nothing to do with "blob being a keyword".

Any way, this works exactly as JPA says it should. You specify a columnDefinition and request "global quoting" and JPA says that global quoting should be applied to columnDefinition.

Which brings us to my proposal. I mean really there is only 2 outcomes here. This is not a bug, so there is nothing to "fix". However, I personally believe that JPA is being too inclusive when it says that columnDefinition (and foreignKeyDefinition) should be quoted due to global quoting being requested. So the only 2 outcomes here are to either:

  1. Do nothing - reject this issue. Again this is not a bug

  2. Allow a configuration option that says that columnDefinition (and foreignKeyDefinition) should be excluded from global quote handling - which is what I proposed

Alessandro Polverini January 8, 2016 at 7:52 PM

But that's because of a bug quoting also keywords, instead of only the identifiers, isn't?

Steve Ebersole January 8, 2016 at 7:48 PM

Well, didn't you say your app failed to start? That seems like a pretty sizeable "downside"

Alessandro Polverini January 8, 2016 at 7:34 PM

I'm sorry if the question is dumb, but what are the downsides of using quoted identifiers?

Steve Ebersole January 8, 2016 at 6:06 PM

Note to you and me that we should discuss this in the documentation section covering naming

Steve Ebersole January 8, 2016 at 5:58 PM

Here is the complete list of category of elements that JPA says should be quoted when global quoting is requested:

  • catalog name

  • schema name

  • table name

  • foreign-key name

  • stored procedure name

  • column name

  • column definition

  • foreign-key definition

For sure the 2 "definition" categories stick out here as ones users would probably want control over being able to opt-out of global quoting.

So I see 2 options here:

  1. Add a simple true/false setting defining whether to exclude definitions ("column definition" and "foreign-key definition") from global quoting

  2. Add a setting for explicit control over the categories to include/exclude from global quoting.

The first option is obviously simpler. But if we are ever going to allow opting out of globally quoting others, I'd rather have the second option then a bunch of additional settings following the first option.

Steve Ebersole October 28, 2015 at 11:16 AM

I'm not sure it matter if you explicitly supply the columnDefinition. Just like if you did not explicitly supply the column name, but requested <delimited-identifiers/> the column name would still be quoted; same applies.

Alessandro Polverini October 28, 2015 at 9:28 AM

BTW: I can't find anymore the "responded" button, so the issue remains in the "awaiting response" status

Alessandro Polverini October 28, 2015 at 9:25 AM

What I was pointing at is that in my project, by simply enabling the globally_quoted_identifiers, generates sql errors even if no columDefinition(s) are used: I get errors even on simple int Ids.
So I suppose something more important broke.

Anyway, your proposal of changing the meaning of the globally_quoted_identifiers to not affect certain things like columnDefinition is sound, and I think it should be proposed like enhancement

Steve Ebersole October 28, 2015 at 3:26 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Steve Ebersole October 27, 2015 at 10:12 PM

Sadly this is something that the JPA spec requires.

JPA 2.1, Section 2.13 Naming of Database Objects

The following annotations contain elements whose values correspond to names of database identifiers
and for which the above rules apply, including when their use is nested within that of other annotations:
...
Column (name, columnDefinition, table elements)
DiscriminatorColumn (name, columnDefinition elements)
...

That's just a small snippet of the quite long list. But as you can see, JPA requires that the columnDefinition be quoted if <delimited-identifiers/> (one source of hibernate.globally_quoted_identifiers) is enabled. I utterly agree with you that quoting columnDefinition, specifically, is generally silly; but we do need to be compliant. So there is nothing we can do here and remain spec compliant.

Well we could define another setting to allow specifying that hibernate.globally_quoted_identifiers should not affect certain things (like columnDefinition). But either way, this is a feature/enhancement request imo.

As a workaround, with 5.0, you could try the (still experimental) "auto keyword quoting" feature.

Fixed

Details

Assignee

Reporter

Labels

Time tracking

0.95h logged

Components

Fix versions

Priority

Created November 10, 2014 at 3:03 PM
Updated January 15, 2025 at 1:59 PM
Resolved January 26, 2016 at 4:16 AM