문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
|
java:hibernate:id_generator [2018/07/11 14:04] kwon37xi [기본 Custom Generator들] |
java:hibernate:id_generator [2023/06/09 10:02] (현재) kwon37xi [UUID] |
||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| ====== Hibernate Primary Key (ID) Generator ====== | ====== Hibernate Primary Key (ID) Generator ====== | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| ===== hibernate.id.new_generator_mappings ===== | ===== hibernate.id.new_generator_mappings ===== | ||
| - | * 최신버전에서는 '' | + | * 최신버전에서는 '' |
| + | * 구버전과의 호환성을 위한 것이 아니면 이 값을 **항상 '' | ||
| * [[http:// | * [[http:// | ||
| * [[http:// | * [[http:// | ||
| + | * [[https:// | ||
| + | |||
| + | ===== UUID ===== | ||
| + | * [[https:// | ||
| + | * 또한 ID Generator는 [[https:// | ||
| + | * 해당 컬럼을 문자열로 지정하고 싶다면 '' | ||
| ===== 기본 Custom Generator들 ===== | ===== 기본 Custom Generator들 ===== | ||
| * [[https:// | * [[https:// | ||
| + | |||
| + | |||
| ==== Sequence에 대한 변화 ==== | ==== Sequence에 대한 변화 ==== | ||
| * 기존방식 : [[https:// | * 기존방식 : [[https:// | ||
| 줄 15: | 줄 26: | ||
| * 기존방식 : [[https:// | * 기존방식 : [[https:// | ||
| * 새 방식 : [[https:// | * 새 방식 : [[https:// | ||
| + | |||
| + | ===== Identity (Auto Increment) ===== | ||
| + | <code java> | ||
| + | @Entity | ||
| + | public class EntityWithIdentityId { | ||
| + | @Id @GeneratedValue(strategy=GenerationType.IDENTITY) Long id; | ||
| + | : | ||
| + | } | ||
| + | </ | ||
| + | * DB에서 ID 값을 읽어와야만 Persistence Context 에 저장가능하기 때문에, 객체 생성후 '' | ||
| + | ===== Sequence ===== | ||
| + | <code java> | ||
| + | @Entity | ||
| + | // Define a sequence - might also be in another class: | ||
| + | @SequenceGenerator(name=" | ||
| + | public class EntityWithSequenceId { | ||
| + | // Use the sequence that is defined above: | ||
| + | @GeneratedValue(strategy=GenerationType.SEQUENCE, | ||
| + | @Id Long id; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Table ===== | ||
| + | <code java> | ||
| + | @Entity | ||
| + | @TableGenerator(name=" | ||
| + | public class EntityWithTableId { | ||
| + | @GeneratedValue(strategy=GenerationType.TABLE, | ||
| + | @Id Long id; | ||
| + | } | ||
| + | </ | ||
| + | |||
| ===== IdGenerator ===== | ===== IdGenerator ===== | ||
| * ID 생성기를 Custom으로 만들 수 있다. | * ID 생성기를 Custom으로 만들 수 있다. | ||
| + | * [[https:// | ||
| * [[http:// | * [[http:// | ||
| * [[http:// | * [[http:// | ||
| 줄 29: | 줄 73: | ||
| String prefix = " | String prefix = " | ||
| - | Connection connection = session.connection(); | + | |
| + | | ||
| try { | try { | ||
| 줄 61: | 줄 106: | ||
| } | } | ||
| </ | </ | ||
| - | * [[https:// | + | * '' |
| + | |||
| + | |||
| + | ===== 참조 ===== | ||
| + | * [[https:// | ||