티스토리 뷰

Skill/JPA

[JPA] DB Table 자동 수정

진열사랑 2021. 2. 3. 00:15

등록일시, 등록 아이디, 수정일시, 수정 아이디 column없는 테이블들 자동으로 column추가됨

application.properties의 효과

spring.jpa.hibernate.ddl-auto=update

 

@MappedSuperclass
@Getter @Setter
public abstract class CommonTbl {
	@Temporal(TemporalType.DATE)
	@Column(name="regist_dt")
	protected Date registDt;

	@Column(name="regist_id")
	protected String registId;

	@Temporal(TemporalType.DATE)
	@Column(name="modify_dt")
	protected Date modifyDt;

	@Column(name="modify_id")
	protected String modifyId;
}
@Entity
@Table(name="t_au_dept")
@NamedQuery(name="TAuDept.findAll", query="SELECT t FROM TAuDept t")
public class TAuDept extends com.metasystem.common.CommonTbl implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name="dept_cd")
	private String deptCd;

	@Column(name="dept_nm")
	private String deptNm;

	@Column(name="upper_dept_cd")
	private String upperDeptCd;

	//bi-directional many-to-one association to TAuUser
	@OneToMany(mappedBy="TAuDept")
	private List<TAuUser> TAuUsers;

	public TAuDept() {
	}

	public String getDeptCd() {
		return this.deptCd;
	}

	public void setDeptCd(String deptCd) {
		this.deptCd = deptCd;
	}

	public String getDeptNm() {
		return this.deptNm;
	}

	public void setDeptNm(String deptNm) {
		this.deptNm = deptNm;
	}

	public String getUpperDeptCd() {
		return this.upperDeptCd;
	}

	public void setUpperDeptCd(String upperDeptCd) {
		this.upperDeptCd = upperDeptCd;
	}

	public List<TAuUser> getTAuUsers() {
		return this.TAuUsers;
	}

	public void setTAuUsers(List<TAuUser> TAuUsers) {
		this.TAuUsers = TAuUsers;
	}

	public TAuUser addTAuUser(TAuUser TAuUser) {
		getTAuUsers().add(TAuUser);
		TAuUser.setTAuDept(this);

		return TAuUser;
	}

	public TAuUser removeTAuUser(TAuUser TAuUser) {
		getTAuUsers().remove(TAuUser);
		TAuUser.setTAuDept(null);

		return TAuUser;
	}

}

console

2021-02-02 23:56:17.592  INFO 18316 --- [           main] org.hibernate.tuple.PojoInstantiator     : HHH000182: No default (no-argument) constructor for class: com.metasystem.word.Word (class must be instantiated by Interceptor)
2021-02-02 23:56:17.610  INFO 18316 --- [           main] org.hibernate.tuple.PojoInstantiator     : HHH000182: No default (no-argument) constructor for class: com.metasystem.domain.TWdWord (class must be instantiated by Interceptor)
2021-02-02 23:56:17.956 DEBUG 18316 --- [           main] org.hibernate.SQL                        : alter table if exists mt_word add column modify_dt date
Hibernate: alter table if exists mt_word add column modify_dt date
2021-02-02 23:56:17.961 DEBUG 18316 --- [           main] org.hibernate.SQL                        : alter table if exists mt_word add column modify_id varchar(255)
Hibernate: alter table if exists mt_word add column modify_id varchar(255)
2021-02-02 23:56:17.962 DEBUG 18316 --- [           main] org.hibernate.SQL                        : alter table if exists mt_word add column regist_dt date
Hibernate: alter table if exists mt_word add column regist_dt date
2021-02-02 23:56:17.963 DEBUG 18316 --- [           main] org.hibernate.SQL                        : alter table if exists mt_word add column regist_id varchar(255)
Hibernate: alter table if exists mt_word add column regist_id varchar(255)
2021-02-02 23:56:17.964 DEBUG 18316 --- [           main] org.hibernate.SQL                        : alter table if exists t_au_dept add column modify_dt date
Hibernate: alter table if exists t_au_dept add column modify_dt date
2021-02-02 23:56:17.966 DEBUG 18316 --- [           main] org.hibernate.SQL                        : alter table if exists t_au_dept add column modify_id varchar(255)
Hibernate: alter table if exists t_au_dept add column modify_id varchar(255)
2021-02-02 23:56:17.967 DEBUG 18316 --- [           main] org.hibernate.SQL                        : alter table if exists t_au_dept add column regist_dt date
Hibernate: alter table if exists t_au_dept add column regist_dt date
2021-02-02 23:56:17.968 DEBUG 18316 --- [           main] org.hibernate.SQL                        : alter table if exists t_au_dept add column regist_id varchar(255)
Hibernate: alter table if exists t_au_dept add column regist_id varchar(255)
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함