Created
January 9, 2018 11:31
-
-
Save Sam-Kruglov/8a2b859ad6e7747f6e4669cd7b07d948 to your computer and use it in GitHub Desktop.
Create PostgreSQL sequence generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Defines common Id Generator that use PostgreSQL sequences properly. | |
* It uses a separate sequence for the chosen ID, as opposed to using a single sequence for all IDs; | |
* the same result can be achieved by simply using {@code @GeneratedValue(strategy = GenerationType.IDENTITY)}, but | |
* that way hibernate would use a sequence as an identity, which would decrease performance. | |
* <p> | |
* Generates a sequence for each entity "entityName_seq" | |
*/ | |
@GenericGenerator(name = "SequencePerEntityGenerator", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", | |
parameters = @Parameter(name = "prefer_sequence_per_entity", value = "true")) | |
package com.samkruglov.entities; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment