Cannot set sequence generator when generator strategy is set to IDENTITY

I am trying to set the size of the selection and the initial value of the sequence using the IDENTITY strategy for PostgreSQL. This does not lead to the expected SQL, however, a change in the SEQUENCE strategy. Is this intended?

id: id: type: integer id: true generator: strategy: IDENTITY sequenceGenerator: sequenceName: table_id_seq allocationSize: 10 initialValue: 100000 
+5
source share
2 answers

Doctrine initializes the ID generator strategy in Doctrine\ORM\Mapping\ClassMetadataFactory . The factory has a large switch , toggling <STRATEGY_NAME> , which you provide in your YAML configuration:

 generator: strategy: <STRATEGY_NAME> 

The selected strategy then extracts additional parameters from your configuration.

All available strategies are listed in the Doctrine Guide . Sequence Generator strategy options are described in detail in the next subsection .

Based on your configuration, you are currently setting parameters for the Sequence Generator strategy, instructing Doctrine to use the Identifier strategy. Perhaps this is an unexpected behavior that you experience?

You can read the source code of the corresponding factory lines to clarify your expectations.

+4
source

So use only with @GeneratedValue (strategy = "SEQUENCE").

For use with @GeneratedValue (strategy = "SEQUENCE"), this annotation allows you to specify sequence details such as increment size and initial sequence values.

other doctrine documentation

Example

config:

 Message: type: entity id: id: type: integer generator: strategy: SEQUENCE sequenceGenerator: sequenceName: message_seq allocationSize: 100 initialValue: 1 

view documentation

+3
source

Source: https://habr.com/ru/post/1213942/


All Articles