Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Markdown
## Fetching
- 데이터베이스에서 데이터를 가져와 응용 프로그램에서 사용할 수 있도록 하는 프로세스

- 언제 데이터를 가져와야 할까?
- 어떻게 데이터를 가져올까?

## 언제 데이터를 가져와야 할까?
- Now : 일반적으로 eager or immediate
- Later : lazy or delayed

### EAGER
```java
@Entity(name = "Department")
public static class Department {

	@Id
	private Long id;

	//Getters and setters omitted for brevity
}

@Entity(name = "Employee")
public static class Employee {

	@Id
	private Long id;

	@NaturalId
	private String username;

	@ManyToOne(fetch = FetchType.EAGER)
	private Department department;

	//Getters and setters omitted for brevity
}
```

```sql
select
    e.id as id1_1_0_,
    e.department_id as departme3_1_0_,
    e.username as username2_1_0_,
    d.id as id1_0_1_
from
    Employee e
left outer join
    Department d
        on e.department_id=d.id
where
    e.id = 1
```

### LAZY

```sql
select
    e.id as id1_1_,
    e.department_id as departme3_1_,
    e.username as username2_1_
from
    Employee e
where
    e.id = 1

select
    d.id as id1_0_0_
from
    Department d
where
    d.id = 1
```
Markdown