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 | 31 |
Tags
- 스프링 핵심 기능
- db
- 스프링 핵심 원리
- Spring Boot
- springdatajpa
- AOP
- http
- 김영한
- jpa
- 알고리즘
- Proxy
- 그리디
- java
- Servlet
- pointcut
- transaction
- spring
- 인프런
- kotlin
- JDBC
- 자바
- Android
- Exception
- JPQL
- QueryDSL
- 백준
- 스프링
- Greedy
- SpringBoot
- Thymeleaf
Archives
- Today
- Total
개발자되기 프로젝트
예제 도메인 모델 본문
1. 도메인 모델
2. Member
package study.querydsl.entity;
import lombok.*;
import javax.persistence.*;
@Entity
@Getter @Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString(of = {"id", "username", "age"})
public class Member {
@Id @GeneratedValue
@Column(name = "member_id")
private Long id;
private String username;
private int age;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "team_id")
private Team team;
public Member(String username, int age, Team team) {
this.username = username;
this.age = age;
if(team != null){
changeTeam(team);
}
}
public Member(String username) {
this(username, 0);
}
public Member(String username, int age) {
this(username, age, null);
}
private void changeTeam(Team team) {
this.setTeam(team);
team.getMembers().add(this);
}
}
3. Team
package study.querydsl.entity;
import lombok.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
@Entity
@Getter @Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString(of = {"id", "name"})
public class Team {
@Id @GeneratedValue
@Column(name = "team_id")
private Long id;
private String name;
@OneToMany(mappedBy = "team")
private List<Member> members = new ArrayList<>();
public Team(String name) {
this.name = name;
}
}
4. GitHub : 210901 Entity Model
'인프런 > [인프런] QueryDsl' 카테고리의 다른 글
결과 조회 (0) | 2021.09.01 |
---|---|
검색조건 쿼리 (0) | 2021.09.01 |
기본 Q-Type (0) | 2021.09.01 |
Querydsl vs JPQL (0) | 2021.09.01 |
Querydsl 설정 및 검증 (0) | 2021.09.01 |
Comments