Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 필기
- java
- 주간회고
- 서평
- algorithms
- 2020년 정보처리기사 4회
- 스터디
- 함수형 코딩
- If
- 회고
- 알고리즘
- post
- 미니프로젝트
- 2020년 제4회 정보처리기사 필기 문제 분석
- 책리뷰
- 코드숨
- 성적프로그램
- Python
- Til
- 뇌정리
- 항해99
- LeetCode
- jsp
- sqldeveloper
- Jackson
- hackerrank
- 정보처리기사
- Real MySQL
- 2020년 일정
- git
Archives
- Today
- Total
조컴퓨터
BaseTimeEntity abstract class 본문
엔티티를 생성하면 공통적으로 들어가는 속성이 있는데, 이는 `생성일자` 와 `수정일자` 이다.
매번 작성하기 보다는 중복으로 발생하는 내용을 상속 받는 구조로 처리할 것이다.
BaseTimeEntity.java
@Getter
@MappedSuperclass
public abstract class BaseTimeEntity {
@CreationTimestamp
@Column(name = "created_at", nullable = false)
private LocalDateTime createdAt;
@UpdateTimestamp
@Column(name = "updated_at", nullable = false)
private LocalDateTime updatedAt;
}
User.java
@Getter
@Entity
public class Users extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "user_id")
private Long userId;
@Column(unique = true, nullable = false)
private String name;
@Column(nullable = false)
private String password;
@Builder
public Users(Long userId, String name, String password) {
this.userId = userId;
this.name = name;
this.password = password;
}
protected Users() {
}
}
프로젝트 진행하면서 배웠는데 참 편리한 기능이라 생각되어 글로 남긴다.
'공부 > JPA' 카테고리의 다른 글
영속성 전이: CASCADE, 고아 객체 (0) | 2022.02.10 |
---|---|
지연 로딩과 즉시 로딩 (0) | 2022.02.10 |
양방향 매핑 시점 (0) | 2022.02.08 |
JPQL 쿼리란 (0) | 2022.02.06 |
[DB] 엔티티(Entity)란 무엇인가 (0) | 2022.02.04 |