[hibernate-dev] HHH-12125 - @GeneratedValue & 5.3

Chris Cranford chris at hibernate.org
Mon Nov 27 10:38:44 EST 2017


Sounds reasonable to me.

On 11/25/2017 12:45 PM, Steve Ebersole wrote:
> I just updated the text for the Jira[1].
>
> Specifically, in the section on SEQUENCE and TABLE, at the moment I have
> kept the legacy behavior of using "hibernate_sequence" as the name of the
> table/sequence - users must opt-in to the behavior of using
> `@GeneratedValue#generator` as the sequence/table name.  I'm thinking I'd
> like to change this though - instead having the default behavior be using
> `@GeneratedValue#generator` as the sequence/table name, and migrators
> opting-out for the old behavior.  I think that is more consistent with how
> I generally view these kind of migration settings.
>
> Any objections to making that switch?
>
> [1] https://hibernate.atlassian.net/browse/HHH-12125
>
>
> On Sat, Nov 25, 2017 at 10:59 AM Vlad Mihalcea <mihalcea.vlad at gmail.com>
> wrote:
>
>> That's a great idea. I stumbled on this issue many times, and it's very
>> good to simplify the mapping as you suggested.
>>
>> +1
>>
>> Vlad
>>
>> On Sat, Nov 25, 2017 at 6:18 PM, Steve Ebersole <steve at hibernate.org>
>> wrote:
>>
>>> The background is all in the Jira, but the crux is this... it is better to
>>> allow a user to do this:
>>>
>>>     @GeneratedValue( strategy=SEQUENCE, generator="my_seq")
>>>
>>> rather than:
>>>
>>>     @GeneratedValue( strategy=SEQUENCE, generator="my_seq")
>>>     @SequenceGenerator( name="my_seq", sequenceName="my_seq" )
>>>
>>> You can see that `SequenceGenerator` is completely unnecessary in this
>>> case
>>> because it adds no new information beyond what is already available on the
>>> `@GeneratedValue`.
>>>
>>> This works great for `GeneratedValue#strategy=SEQUENCE` and
>>> `GeneratedValue#strategy=TABLE`, however consider this mapping:
>>>
>>>     @GeneratedValue( strategy=AUTO, generator="increment" )
>>>     @GenericGenerator( name = "increment", strategy = "increment" )
>>>
>>> Here we have the same underlying concern - the `@GenericGenerator` is just
>>> noise, it adds no additional information.  In keeping with the work done
>>> as
>>> part of HHH-12125 it would be great to allow users to instead just say:
>>>
>>>     @GeneratedValue( strategy=AUTO, generator="increment" )
>>>
>>> The problem here is that this last one is actually the responsibility of
>>>
>>> `org.hibernate.boot.model.IdGeneratorStrategyInterpreter#determineGeneratorName`
>>> to interpret, but it is not passed the `GeneratedValue#generator` value.
>>>
>>> So the easiest solution would be to add an additional parameter to
>>> `IdGeneratorStrategyInterpreter#determineGeneratorName` for passing in the
>>> generator name.  The concern here is that `IdGeneratorStrategyInterpreter`
>>> is defined in the API space and could very well have custom impls.
>>>
>>> A lesser solution wold be to add checks to the code that calls
>>> `IdGeneratorStrategyInterpreter#determineGeneratorName` to check for
>>> "magic" generator names before asking the
>>> `IdGeneratorStrategyInterpreter`.  This is just a very inflexible and
>>> non-extensible solution, but maybe this works for 5.3 and we can adjust
>>> `IdGeneratorStrategyInterpreter` as part of 6.0.
>>>
>>> Thoughts?
>>>
>> _______________________________________________
>>> hibernate-dev mailing list
>>> hibernate-dev at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>>
>>
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev



More information about the hibernate-dev mailing list