Indicates a select operation.
The annotated method must be a member of a Dao annotated interface.
@Entity
public class Employee {
...
}
@Dao
public interface EmployeeDao {
@Select
String selectNameById(Integer id);
@Select
List<Employee> selectNamesByAgeAndSalary(Integer age, BigDecimal salary);
@Select
Employee selectById(Integer id);
@Select
List<Employee> selectByExample(Employee example);
@Select(strategy = SelectStrategyType.STREAM)
<R> R selectSalary(Integer departmentId, Function<Stream<BigDecimal>, R> mapper);
}
The method may throw following exceptions:
DomaNullPointerExceptionif any of the method parameters arenullSqlFileNotFoundExceptionifsqlFileistrueand a SQL file is not foundUnknownColumnExceptionif a property whose mapped column is included in a result set is not foundNonUniqueResultExceptionif an unique row is expected but two or more rows are found in a result setNonSingleColumnExceptionif a single column is expected but two or more columns are found in a result setNoResultExceptionifensureResult()istrueand no row is found in a result setResultMappingExceptionifensureResultMapping()istrueand all entity properties are not mapped to columns of a result setJdbcExceptionif a JDBC related error occurs
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<?>Defines how an aggregate is constructed.booleanWhether to ensure that one or more rows are found in a result set.booleanWhether to ensure that all entity properties are mapped to columns of a result set.intThe fetch size.The naming convention for keys ofMap<Object, String>.intThe maximum number of rows.intThe query timeout in seconds.
-
Element Details
-
queryTimeout
int queryTimeoutThe query timeout in seconds.If not specified,
Config.getQueryTimeout()is used.- Returns:
- the query timeout
- See Also:
- Default:
- -1
-
fetchSize
int fetchSizeThe fetch size.If not specified,
Config.getFetchSize()is used.- Returns:
- the fetch size
- See Also:
- Default:
- -1
-
maxRows
int maxRowsThe maximum number of rows.If not specified,
Config.getMaxRows()is used.- Returns:
- the maximum number of rows
- See Also:
- Default:
- -1
-
strategy
SelectType strategy- Returns:
- the strategy for handling objects mapped to a result set.
- Default:
- RETURN
-
fetch
FetchType fetch- Returns:
- the fetch type.
- Default:
- LAZY
-
ensureResult
boolean ensureResultWhether to ensure that one or more rows are found in a result set.if
trueand no row is found,NoResultExceptionis thrown from the method.- Returns:
- whether to ensure that one or more rows are found in a result set
- Default:
- false
-
ensureResultMapping
boolean ensureResultMappingWhether to ensure that all entity properties are mapped to columns of a result set.This value is used only if the result set is fetched as an entity or a entity list.
If
trueand there are some unmapped properties、ResultMappingExceptionis thrown from the method.- Returns:
- whether to ensure that all entity properties are mapped to columns of a result set
- Default:
- false
-
mapKeyNaming
MapKeyNamingType mapKeyNamingThe naming convention for keys ofMap<Object, String>.This value is used only if a result set is fetched as
Map<Object, String>orList<Map<Object, String>>.- Returns:
- the naming convention
- Default:
- NONE
-
sqlLog
SqlLogType sqlLog- Returns:
- the output format of SQL logs.
- Default:
- FORMATTED
-
aggregateStrategy
Class<?> aggregateStrategyDefines how an aggregate is constructed.Specifies the interface annotated with
AggregateStrategy.- Returns:
- the class representing the aggregation strategy, or
Void.classif not specified
- Default:
- java.lang.Void.class
-