This file contains hidden or 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
| @Entity | |
| @Table(name = "groups") | |
| public class Group implements Identifiable<Long> { | |
| @Id | |
| @GeneratedValue(generator = "SequencePerEntityGenerator") | |
| private Long id; // getter | |
| @Column(nullable = false, unique = true) | |
| private String name; // getter and setter |
This file contains hidden or 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
| @Entity | |
| @Table(name = "users") | |
| public class User implements Identifiable<Long> { | |
| @Id | |
| @GeneratedValue(generator = "SequencePerEntityGenerator") | |
| private Long id; // only getter | |
| @Column(length = 16, nullable = false, unique = true) | |
| private String username; // getter and setter |
This file contains hidden or 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")) |
NewerOlder