Statements
The JPQL supports select, update, and delete statements. Kotlin JDSL provides a DSL to build them.
Select statement
Call select()
in jpql()
to build a select statement.
Select clause
Use select()
and pass Expression
to build a select clause in the select statement. If you pass only one Expression
to select()
, it will infer a return type from Expression
. However, if you pass more than one Expression
, you need to specify the type as it cannot infer the type.
DTO projection
Specify a DTO class and pass parameters of the constructor to selectNew()
to build a DTO projection.
From clause
Use from()
and pass Entity and Join to specify the entities for selection when building a from clause in the select statement.
Join
Use join()
and fetchJoin()
to combine the entities for selection. There are two types of join()
: Join and Association Join This is distinguished by whether join()
is used between two unrelated entities or between two related entities.
Call as()
after join()
to alias the entity being joined. This can be useful if you use multiple entities with the same type in a from clause.
Where clause
Use where()
and pass Predicate to restrict the data when building a where clause in the select statement. You can use whereAnd()
as a short form of where()
and and()
. You can also use whereOr()
as a short form of where()
and or()
.
Group by clause
Use groupBy()
and pass Expression to create unique groups of data when building a group by clause in the select statement.
Having clause
Use having()
and pass Expression to further restrict the data when building a having clause in the select statement. You can use havingAnd()
as a short form of having()
and and()
. You can also use havingOr()
as a short form of having()
and or()
.
Order by clause
Use orderBy()
and pass Sort to return data in the declared order when building an order by clause in the select statement.
Update statement
Call update()
in jpql()
to build an update statement.
Update clause
Use update()
and pass Entity to specify the entity to modify when building an update clause in the update statement.
Set clause
Use set()
and pass Expression to assign values when building a set clause in the update statement. You can use multiple assignments by adding set()
after set()
.
Where clause
Use where()
and pass Predicate to restrict the data when building a where clause in the update statement. You can use whereAnd()
as a short form of where()
and and()
. You can also use whereOr()
as a short form of where()
and or()
.
Delete statement
Call deleteFrom()
in jpql()
to build a delete statement.
Delete from clause
Use deleteFrom()
and pass Entity to specify the entity to delete when building a delete from clause in the delete statement.
Where clause
Use where()
and pass Predicate to restrict the data when building a where clause in the delete statement. You can use whereAnd()
as a short form of where()
and and()
. You can also use whereOr()
as a short form of where()
and or()
.
Last updated