Fixed
Details
Assignee
Steve EbersoleSteve EbersoleReporter
Steve EbersoleSteve EbersoleFix versions
Priority
Major
Details
Details
Assignee
Steve Ebersole
Steve EbersoleReporter
Steve Ebersole
Steve EbersoleFix versions
Priority
Created November 25, 2017 at 12:28 AM
Updated January 18, 2018 at 4:00 AM
Resolved November 25, 2017 at 12:30 AM
Historically Hibernate always expects that
@GeneratedValue
is matched with a matching named "generator definition". The name is provided byGeneratedValue#generator
. The corresponding "generator definition" would be a@GenericGenerator
,@SequenceGenerator
or@TableGenerator
based on the value ofGeneratedValue#strategy
:SEQUENCE
andTABLE
Given
@GeneratedValue( strategy=SEQUENCE, ... )
Hibernate would look for a matching@GenericGenerator
or a@SequenceGenerator
.Given
@GeneratedValue( strategy=TABLE, ... )
Hibernate would look for a matching@GenericGenerator
or a@TableGenerator
.Again, it would be an error if Hibernate did not find the matching
@GenericGenerator
,@SequenceGenerator
or@TableGenerator
. Ultimately though, these generator definitions are really just about handling non-default situations (e.g., use a specific increment size for a sequence/table, etc). But it should be ok for the user to leave them off and just get the "default behavior" (e.g. increment size of 50 as JPA defines for@SequenceGenerator
and@TableGenerator
).In other words, this should be a valid mapping:
Here we would pick up the JPA defined defaults (see
@SequenceGenerator
and@TableGenerator
for the defined defaults).The name is an additional discussion, and is the same discussion for:
In both cases we do not provide an explicit
@SequenceGenerator#sequenceName
value. Historically Hibernate interprets the default name for both sequence and table as"hibernate_sequence"
. Ideally though (keeping with the theme of@SequenceGenerator
and@TableGenerator
defining just overrides) we'd want the sequence here to be named"my_db_sequence"
.So another part of the work here is to support this distinction - by a setting
hibernate.model.generator_name_as_sequence_name
. By default, this istrue
which means we will pick"my_db_sequence"
(@GeneratedValue#generator
)); setting that tofalse
indicates to pick the legacy"hibernate_sequence"
name.IDENTITY
This discussion has no bearing on how
GenerationType#IDENTITY
is handled.AUTO
In keeping with "less typing == better", this also covers some cases related to
GenerationType#AUTO
specifically in howorg.hibernate.boot.model.IdGeneratorStrategyInterpreter#determineGeneratorName
can operate. This work changes the "parameter object" passed in to that method to give it access to the@GeneratedValue#generator
value. At the moment, this only case this is used is to handle:Previously this mapping would not work. Instead a user would have to say:
"increment" generator is a Hibernate-specific, in-memory strategy performing simple incrementing for generating id values. Specifically it is a short-name for Hibernate's
org.hibernate.id.IncrementGenerator
. Generally speaking there is little need to configureIncrementGenerator
, so requiring the@GenericGenerator
is unnecessary in most cases.