[hibernate-dev] "matching" table/column names (and naming strategies)

andrea boriero andrea at hibernate.org
Thu Jul 7 09:57:16 EDT 2016


On 7 July 2016 at 15:43, Steve Ebersole <steve at hibernate.org> wrote:

> On Thu, Jul 7, 2016 at 3:58 AM andrea boriero <andrea at hibernate.org>
> wrote:
>
>> On 6 July 2016 at 21:01, Steve Ebersole <steve at hibernate.org> wrote:
>>
>>>
>>> One option is that they need to match exactly (maybe with some simple
>>> handling of quoted versus case-insensitive, similar to Identifier#equals
>>> leveraging Identifier#getCanonicalName), e.g.:
>>>
>>> @Entity
>>> @Table( name="`USER`" )
>>> @org.hibernate.annotations.Table( appliesTo="`USER`", ... )
>>> class User {
>>>     ...
>>> }
>>>
>>> I guess the first question here is whether we want to support referring
>>> to
>>> implicit table names in other annotations at all.  JPA for the most part
>>> discourages this; in order for a table name to be referenced in other
>>> annotations it should be named explicitly.
>>>
>>> In my opinion make sense not supporting implicit naming strategy.
>>
>
> I was not so much asking about leveraging the ImplicitNamingStrategy.
> More I was asking conceptually whether we want to allow this at all.
>

+1 for requiring explicitly naming tables and columns in order to be
referred in annotations.

>
> What about comparing the names after having previously removed, if
>> presents, the quoting chars?
>>
>
> Personally, I think using straight String comparisons is the main
> problem.  If you look at the code for Identifier#equals that is really
> exactly what we need already.
>
> We cannot just drop the quotes for an accurate comparison.  "`MY_TABLE`"
> and "`my_table`" are different tables to each sane and SQL spec compliant
> database.  But conversely "MY_TABLE" and "my_table" are the same table.
>

That's true, so if one or both names are quoted, we can remove the quoting
chars and do a case-sensitive comparison otherwise we we can do a
case-insensitive comparison, am I right?

>
> Overall though I think it is reasonable to just expect to match an
> explicit name.  Especially if we
> allow org.hibernate.annotations.Table#appliesTo to be empty
> like javax.persistence.Column#table, etc as a means to refer to the root
> table.
>
>


More information about the hibernate-dev mailing list