@MappedSuperclass
@EntityListeners(value = {AuditingEntityListener.class})
@Getter
public class BaseEntity {
@CreatedDate
@Column(name = "regdate", updatable = false)
private LocalDateTime regDate;
@LastModifiedDate
@Column(name = "moddate")
private LocalDateTime modDate;
}
// Application class에 @EnableJpaAuditing 추가
@EnableJpaAuditing : 생성일자, 수정일자 자동으로 등록
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@ToString
public class Movie {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long mno; // movie 번호
private String title; // 제목
}
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@ToString(exclude = "movie") // movie entity와 연관관계를 가짐을 명시
public class MovieImage {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long inum; // image 번호
private String uuid;
private String imaName;
private String path;
// M:1 (Lazy Fetch 진행)
@ManyToOne(fetch = FetchType.LAZY)
private Movie movie;
}
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@ToString
@Table(name = "m_member")
public class Member extends BaseEntity{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long mid;
private String email;
private String pw;
private String nickname;
}
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@ToString (exclude = {"movie", "m_member"})
public class Review extends BaseEntity{
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
private Long reviewnum;
@ManyToOne(fetch = FetchType.LAZY)
private Movie movie; // Movie Entity와 일대다 관계
@ManyToOne(fetch = FetchType.LAZY)
private Member member; // Member Entity와 일대다 관계
private int grade;
private String text;
}