11-15 08:50
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[JPA] ORACLE JPA ์‹œํ€€์Šค ์ƒ์„ฑ ์ ์šฉ / ORA-02289: ์‹œํ€€์Šค๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• ๋ณธ๋ฌธ

WebApp/Spring

[JPA] ORACLE JPA ์‹œํ€€์Šค ์ƒ์„ฑ ์ ์šฉ / ORA-02289: ์‹œํ€€์Šค๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

miinsun 2022. 2. 5. 20:52

 

๐Ÿ“Œ ์›์ธ : ์˜ค๋ผํด์€ mySql๊ณผ ๋‹ค๋ฅด๊ฒŒ id ์ž๋™ ์ฆ๊ฐ€๊ฐ€ ๋ถˆ๊ฐ€ํ•˜๋‹ค.

 

๐Ÿ“Œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

JPA๋ฅผ ํ†ตํ•ด ์‹œํ€€์Šค ์ƒ์„ฑ๊ธฐ๋ฅผ ๋งŒ๋“ค์–ด์„œ @ID ๊ฐ’์— ์ง์ ‘ ์ฃผ์ž…ํ•ด์ฃผ์ž

 

1. DB์— ์‹œํ€€์Šค ์ƒ์„ฑ

CREATE SEQUENCE FOLDER_SEQ START WITH 1 INCREMENT BY 1;

 

2. ์‹œํ€€์Šค ์ƒ์„ฑ๊ธฐ ๋งŒ๋“ค๊ธฐ

@SequenceGenerator(
		name = "FOLDER_SEQ_GENERATOR"
	    , sequenceName = "FOLDER_SEQ"
	    , initialValue = 1
	    , allocationSize = 1
	)
public class Folder implements Serializable{
...
}

 

3. ์‹œํ€€์Šค ์ ์šฉ

@Id
@Column(name="folder_Id")
@GeneratedValue(
    strategy = GenerationType.SEQUENCE
    , generator = "FOLDER_SEQ_GENERATOR"
)
private int folderId;

 

 

 

๐Ÿ“Œ ์ „์ฒด ์ฝ”๋“œ

package com.dalc.one.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@SuppressWarnings("serial")
@Entity
@Table(name="folder")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@SequenceGenerator(
		name = "FOLDER_SEQ_GENERATOR"
	    , sequenceName = "FOLDER_SEQ"
	    , initialValue = 1
	    , allocationSize = 1
	)
public class Folder implements Serializable{
	@Id
	@Column(name="folder_Id")
	@GeneratedValue(
    	strategy = GenerationType.SEQUENCE
    	, generator = "FOLDER_SEQ_GENERATOR"
    )
	private int folderId;
	
	@Column(name="user_id")
	private String userId;
	
	@Column(name="folder_name")
	private String folderName;
}

 

๐Ÿ“Œ ํ•ด๊ฒฐ ์™„๋ฃŒ

 

Comments