/Hibernate_Udemy

https://www.udemy.com/course/spring-alishev/learn/lecture/31012638#overview

Primary LanguageJavaApache License 2.0Apache-2.0

Hibernate_UDEMY

To the Spring Framework Course by Nail Alishev https://www.udemy.com/course/spring-alishev/learn/lecture/31012638#overview

Entity

package org.example.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "Person")
public class Person {
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

...
}

strategy = GenerationType.IDENTITY means that the process of key generation for id will be completely performed on the Postgres-side.

An Example code for strategy = GenerationType.SEQUENCE:

@GeneratedValue(strategy = GenerationType.SEQUENCE,
    generator = "seq_generator_person")
@SequenceGenerator(name = "seq_generator_person",
    sequenceName = "person_id_seq",
    allocationSize = 1)