1. Springboot JPA Oracle 연동 설정

 

| application.properties 연결정보 입력

spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@10.110.15.57/PLMDEV2
spring.datasource.username=wcadmin
spring.datasource.password=wcadmin

spring.jpa.hibernate.ddl-auto=create
spring.jpa.generate-ddl=false
spring.jpa.show-sql=true
spring.jpa.database=oracle

logging.level.org.hibernate=info

spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

 

| JPA를 활용한 테이블 생성

package com.kyhslam.domain;

import java.sql.Timestamp;

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

import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;


@Entity
@Table(name="tbl_boards")
public class Board {

	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long bno;
	private String title;
	private String writer;
	private String content;
	
	@CreationTimestamp
	private Timestamp regdate;
	
	@UpdateTimestamp
	private Timestamp updatedate;
	
	
	public Long getBno() {
		return bno;
	}
	public void setBno(Long bno) {
		this.bno = bno;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getWriter() {
		return writer;
	}
	public void setWriter(String writer) {
		this.writer = writer;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public Timestamp getRegdate() {
		return regdate;
	}
	public void setRegdate(Timestamp regdate) {
		this.regdate = regdate;
	}
	public Timestamp getUpdatedate() {
		return updatedate;
	}
	public void setUpdatedate(Timestamp updatedate) {
		this.updatedate = updatedate;
	}
}

 

 

애플리케이션을 빌드 하면 아래와 같이 쿼리가 실행되며 테이블이 생성되는 걸 볼 수 있다.

로그를 보면 테이블이 생성되는 것을 볼 수 있다.

 

 

 


| application.yml 파일일 경우

# Database
spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/springboot
    username: postgres
    password: 1234
    driver-class-name: org.postgresql.Driver

# JPA
  jpa:
    database: postgresql
    database-platform: org.hibernate.dialect.PostgreSQLDialect
    hibernate:
      ddl-auto: create
    properties:
      hibernate:
#        show-sql: true # System.out을 통해 찍는다.
        format_sql: true
        jdbc.lob.non_contextual_creation: true

logging:
  level:
    org.hibernate.SQL: debug
    org.hibernate.type: trace # 파라미터 보여준다.

 

댓글

Designed by JB FACTORY