Entities

Kotlin JDSL์€ JPQL์˜ entity๋ฅผ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด Entity ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. Entity๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด, entity()๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

entity(Book::class)

Alias

๋ชจ๋“  Entity๋Š” alias๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ entity()์— alias๋ฅผ ๋ช…์‹œํ•˜์ง€ ์•Š์œผ๋ฉด Kotlin JDSL์ด class ๋ช…์„ ํ†ตํ•ด ์ž๋™์œผ๋กœ alias๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. Entity๋Š” alias๋ฅผ ํ†ตํ•ด ๊ตฌ๋ถ„์ด ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋งŒ์•ฝ ๋™์ผํ•œ ํƒ€์ž…์˜ Entity๋ฅผ ํ•˜๋‚˜ ์ด์ƒ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ์ด Entity๋“ค์„ ๊ตฌ๋ณ„ํ•˜๊ธฐ ์œ„ํ•ด์„œ alias๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

entity(Book::class)
entity(Book::class, Book::class.simpleName!!)

entity(Book::class, alias = "book1")
entity(Book::class, alias = "book2")

Expression

Entity๋Š” select clause ๋‚˜ predicate ๋“ฑ์—์„œ Expression์œผ๋กœ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

// SELECT b FROM Book AS b WHERE b.isbn.value = :param1
jpql {
    select(
        entity(Book::class, "b"),
    ).from(
        entity(Book::class, "b"),
    ).where(
        entity(Book::class, "b")(Book::isbn)(Ibsn::value).eq("01"),
    )
}

Treat

Entity์˜ ํƒ€์ž…์„ ์ž์‹ ํƒ€์ž…์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ธฐ ์œ„ํ•ด, treat()๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

entity(Employee::class).treat(FullTimeEmployee::class)

Last updated