📘
Kotlin JDSL
Discord
en
en
  • Kotlin JDSL
  • JPQL with Kotlin JDSL
    • Statements
    • Entities
    • Paths
    • Expressions
    • Predicates
    • Sorts
    • Subqueries
    • Custom DSL
    • Spring supports
    • Migration 2.X to 3.X
  • Kotlin JDSL Roadmap
  • FAQ
    • How can I see the generated query?
    • How can I use Kotlin value class?
    • What is the difference between Kotlin JDSL and jOOQ and QueryDSL?
    • Why is there a support module that only has a nullable return type
Powered by GitBook
On this page
  • Alias
  • Expression
  • Treat

Was this helpful?

Edit on GitHub
  1. JPQL with Kotlin JDSL

Entities

PreviousStatementsNextPaths

Last updated 1 year ago

Was this helpful?

Kotlin JDSL has the Entity interface to represent an entity in JPQL. Use entity() to build Entity.

entity(Book::class)

Alias

All Entity has an alias. If you don't specify an alias in entity(), Kotlin JDSL automatically generates an alias from the class name. Entity is identified by its alias. If you use more than one Entity with the same type, you need to alias them to identify each Entity.

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

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

Expression

Entity can be used as in a or .

// 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

Use treat() to typecast Entity to subclass.

entity(Employee::class).treat(FullTimeEmployee::class)
Expression
predicate
select clause