๐Ÿ“ RDBMS

๋ฐ์ดํ„ฐ๋“ค์˜ ์ง‘ํ•ฉ์„ ๊ด€๊ณ„ํ˜•์œผ๋กœ ํ‘œํ˜„ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ํ–‰๊ณผ ์—ด์˜ ์ง‘ํ•ฉ์œผ๋กœ ๊ตฌ์„ฑ๋œ ํ…Œ์ด๋ธ”์˜ ๋ฌถ์Œ ํ˜•์‹์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ œ๊ณตํ•œ๋‹ค. ํ…Œ์ด๋ธ” ํ˜•์‹์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์กฐ์ž‘ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ด€๊ณ„ ์—ฐ์‚ฐ์ž๋ฅผ ์ œ๊ณตํ•œ๋‹ค.

๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค์˜ ํŠน์„ฑ

  1. ์‹ค์‹œ๊ฐ„ ์ ‘๊ทผ์„ฑ (Real-tiem Accessability)
  2. ๊ณ„์†์ ์ธ ๋ณ€ํ™” (Continuous Evolution) - ์ •ํ™•ํ•œ ๊ฐ’์„ ์œ ์ง€ํ•˜๊ธฐ์œ„ํ•ด ์‚ฝ์ž…,์‚ญ์ œ,์ˆ˜์ • ๋“ฑ์„ ์ด์šฉํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ์ง€์†์ ์œผ๋กœ ๊ฐฑ์‹  ํ•  ์ˆ˜ ์žˆ๋‹ค.
  3. ๋™์‹œ ๊ณต์œ ์„ฑ (Concurrent Sharing)
  4. ๋‚ด์šฉ ์ฐธ์กฐ (Content Reference) - ์ €์žฅํ•œ ๋ฐ์ดํ„ฐ ๋ ˆ์ฝ”๋“œ์˜ ์œ„์น˜๋‚˜ ์ฃผ์†Œ๊ฐ€ ์•„๋‹Œ ์‚ฌ์šฉ์ž๊ฐ€ ์š”๊ตฌํ•˜๋Š” ๋ฐ์ดํ„ฐ์˜ ๋‚ด์šฉ, ์ฆ‰ ๋ฐ์ดํ„ฐ ๊ฐ’์— ๋”ฐ๋ผ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค.

    ํฌ์ธํ„ฐ ๊ฐ™์€ ์ฃผ์†Œ ๊ฐœ๋…์ด ์•„๋‹ˆ๋ผ, ๊ฒ€์ƒ‰์—”์ง„์ฒ˜๋Ÿผ ํ‚ค์›Œ๋“œ ๋‚ด์šฉ์„ ๊ฒ€์ƒ‰ํ•˜๋Š”๊ฒƒ ์ฒ˜๋Ÿผ ์ž‘๋™ํ•œ๋‹ค.

ORM๊ณผ JPA๊ทธ๋ฆฌ๊ณ  Hibernate

๐Ÿ’ฅ ORM (Object Relational Mappin)

ORM์ด๋ž€ ๊ฐ์ฒด์™€ DB์˜ ํ…Œ์ด๋ธ”์ด ๋งคํ•‘์„ ์ด๋ฃจ๋Š” ๊ฒƒ์„ ๋งํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰ ๊ฐ์ฒด๊ฐ€ ํ…Œ์ด๋ธ”์ด ๋˜๋„๋ก ๋งคํ•‘ ์‹œ์ผœ์ฃผ๋Š” ๊ฒƒ์„ ๋งํ•ฉ๋‹ˆ๋‹ค. ORM์„ ์ด์šฉํ•˜๋ฉด SQL Query๊ฐ€ ์•„๋‹Œ ์ง๊ด€์ ์ธ ์ฝ”๋“œ(๋ฉ”์„œ๋“œ)๋กœ์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์กฐ์ž‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐ŸŒ‰ JPA (Java Persistence API)

Mybatis์—์„œ๋Š” ํ…Œ์ด๋ธ” ๋งˆ๋‹ค ๋น„์Šทํ•œ CRUD SQL์„ ๊ณ„์† ๋ฐ˜๋ณต์ ์œผ๋กœ ์‚ฌ์šฉํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค.
์†Œ๊ทœ๋ชจ๋ผ๋„ Mybatis๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค์–ด ๋ณด์…จ๋‹ค๋ฉด, DAO ๊ฐœ๋ฐœ์ด ๋งค์šฐ ๋ฐ˜๋ณต๋˜๋Š” ์ž‘์—…์ด๋ฉฐ, ์ด ์ž‘์—…์ด ๋งค์šฐ ๊ท€์ฐฎ๋‹ค๋Š” ๊ฒฝํ—˜์„ ํ•ด๋ณด์•˜์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋˜ํ•œ ํ…Œ์ด๋ธ”์— ์นผ๋Ÿผ์ด ํ•˜๋‚˜ ์ถ”๊ฐ€๋œ๋‹ค๋ฉด ์ด์™€ ๊ด€๋ จ๋œ ๋ชจ๋“  DAO์˜ SQL๋ฌธ์„ ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰ DAO์™€ ํ…Œ์ด๋ธ”์€ ๊ฐ•ํ•œ ์˜์กด์„ฑ์„ ๊ฐ–๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฐ์ฒด ๋ชจ๋ธ๋ง๋ณด๋‹ค ๋ฐ์ดํ„ฐ ์ค‘์‹ฌ ๋ชจ๋ธ๋ง(ํ…Œ์ด๋ธ” ์„ค๊ณ„)์„ ์šฐ์„ ์‹œ ํ–ˆ์œผ๋ฉฐ, ๊ฐ์ฒด์ง€ํ–ฅ์˜ ์žฅ์ (์ถ”์ƒํ™”, ์บก์Šํ™”, ์ •๋ณด์€๋‹‰, ์ƒ์†, ๋‹คํ˜•์„ฑ)์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๊ฐ์ฒด๋ฅผ ๋‹จ์ˆœํžˆ ๋ฐ์ดํ„ฐ ์ „๋‹ฌ ๋ชฉ์ ( VO, DTO )์—๋งŒ ์‚ฌ์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. - ๐Ÿ“ ORM๊ณผ JPA ๊ทธ๋ฆฌ๊ณ  Hibernate

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ํด๋ž˜์Šค ์„ค๊ณ„์‹œ ์ƒ์‚ฐํ•˜๋Š” DAO์— JPA๋ฅผ ์ƒ์†๋ฐ›์€ ์ƒํƒœ๋กœ ๊ฐ์ฒด์˜ ์„ ์–ธ์‹œ DAO์˜ ๋ฉ”์†Œ๋“œ๋ฅผ ํ™œ์šฉํ•ด ORM๊ณผ์ •์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

์ฝ”๋“œ๋กœ ํ‘œํ˜„ํ•ด๋ณด์ž๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

public interface PostDAO extends JpaRepository<Post, Integer>{

	Page<Post> findByCategoryId(int categoryId, Pageable pageable);

	@Query("Select p from Post p where p.push >= 5")
	public Page<Post> Push(Pageable pageable);

}

์œ„์ฒ˜๋Ÿผ JpaRepository<๊ฐ์ฒด, PK>์˜ ํ˜•ํƒœ๋กœ ์ƒ์†๋ฐ›์€ ํ›„

@RequestMapping("/list/recommend")
	public String Recommend(Model model, @RequestParam(value="category", required = false, defaultValue = "0") int categoryId,
			@PageableDefault(sort = {"id"}, direction = Sort.Direction.DESC, size = 10) Pageable pageable) {

		Page<Post> postPage;

		postPage = postDAO.Push(pageable);
		model.addAttribute("postPage", postPage);

		...
	}

์™€ ๊ฐ™์ด JPA๋Š” DAO๋ฅผ ํ†ตํ•ด ORM์„ ๊ฑฐ์นœ ํ…Œ์ด๋ธ”์„ postPage๋ผ๋Š” ๊ฐ์ฒด์— ํ• ๋‹นํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์„ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•œ๋‹ค.

Hibernate

Boss์—์„œ ๊ฐœ๋ฐœํ•œ ORM ํ”„๋ ˆ์ž„์›Œํฌ

Hibernate๋Š” ํ•˜๋‚˜๋ถ€ํ„ฐ ์—ด๊นŒ์ง€ OR๋งคํ•‘์„ ํ•˜๊ณ ์ž ํ• ๋•Œ ๊ฐ€์žฅ ์ข‹๋‹ค. ์ด๋Š” ์™„๋ฒฝํ•œ ORM์†”๋ฃจ์…˜์„ ์ œ๊ณตํ•˜์ง€๋งŒ ์ฟผ๋ฆฌ์— ๋Œ€ํ•œ ์ œ์–ด๋ฅผ ์–ด๋ ต๊ฒŒ ํ•œ๋‹ค. Hibernate๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ฐ๊ฐ์— ๋Œ€ํ•œ ์„ค๊ณ„์— ๋Œ€ํ•œ ์™„๋ฒฝํ•œ ํ†ต์ œ๊ฐ€ ๊ฐ€๋Šฅํ•œ ์ƒํ™ฉ์—์„œ ์ด์ƒ์ ์ธ ์†”๋ฃจ์…˜์ด๋‹ค. - ๐Ÿ“ Hibernate, JPA, and Mybatis Which is right for you?

๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ๊ด€๋ฆฌ์˜ ์žฅ์ 

  • ๋ฐ์ดํ„ฐ์˜ ์ผ๊ด€์„ฑ ๋ฐ ๋ฌด๊ฒฐ์„ฑ ์œ ์ง€ - ์—ฐ๊ด€์žˆ๋Š” ์ƒํ˜ธ๊ฐ„์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์œ ์ง€๋˜์–ด์•ผ ํ•˜๋Š” ํŠน์„ฑ๋•์— ์ˆ˜์ •์ด๋‚˜ ์‚ญ์ œ๊ฐ€ ํ•œ๊ณณ์—์„œ๋งŒ ์ผ์–ด๋‚  ๊ฒฝ์šฐ ์—๋Ÿฌ ๋ฐœ์ƒ
  • ๋ฐ์ดํ„ฐ์˜ ์ค‘๋ณต ์ตœ์†Œํ™”
  • ๋ฐ์ดํ„ฐ ๋ณด์•ˆ ๋ณด์žฅ

๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ๊ด€๋ฆฌ์˜ ๋‹จ์ 

  • ์šด์˜๋น„๊ฐ€ ๋น„์‹ธ๋‹ค
  • ๋ฐฑ์—… ๋ฐ ๋ณต๊ตฌ์— ๋Œ€ํ•œ ๊ด€๋ฆฌ๊ฐ€ ๋ณต์žก
  • ๋ถ€๋ถ„์  ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ์†์‹ค์ด ์ „์ฒด ์‹œ์Šคํ…œ์„ ์ •์ง€