Find One By
Definition
The findOneBy method allows you to get one record of a table filtered by the conditions that are supplied.
caution
If the constructed query returns 0 or more than one record, this method will return a null KRow.
Available methods
findOneBy(KFindFunction<KFrom, KQuery> kFindFunction, KColumnAllowedToSelect... selects): Receives aKFindFunctionthat allows adding conditions to the base query and a variable quantity of columns and values that will be added to theSELECTlist. Among the possible values are:KTableColumn,KColumn,Values,KCondition,Columns with over,Columns with alias,KRaw,Case conditional expression.findOneBy(String jdbc, KFindFunction<KFrom, KQuery> kFindFunction, KColumnAllowedToSelect... selects): Receives the name of datasource connection to which you need to connect, aKFindFunctionthat allows adding conditions to the base query and a variable quantity of columns and values that will be added to theSELECTlist. Among the possible values are:KTableColumn,KColumn,Values,KCondition,Columns with over,Columns with alias,KRaw,Case conditional expression.
Example: KFindFunction, KColumnAllowedToSelect...
Java code:
final Language language =
languageRepository.findOneBy(
(KFrom kFrom) ->
kFrom
.where(LANGUAGE.ID.eq(7L)),
LANGUAGE.ID,
LANGUAGE.NAME
);
SQL generated:
SELECT la.id, la.name
FROM language la
WHERE la.id = ?1
Parameters:
- ?1: 7
Example: String, KFindFunction, KColumnAllowedToSelect...
Java code:
final Language language =
languageRepository.findOneBy(
K.JDBC_LEGACY,
(KFrom kFrom) ->
kFrom
.where(LANGUAGE.ID.eq(7L)),
LANGUAGE.ID,
LANGUAGE.NAME
);
SQL generated:
SELECT la.id, la.name
FROM language la
WHERE la.id = ?1
Parameters:
- ?1: 7