You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Join queries will likely require you to define a MyBatis result mapping in XML. This is the only instance where XML is required. This is due to the limitations of the MyBatis annotations when mapping collections.
66
+
Join queries will likely require you to define a MyBatis result mapping in XML. This is the only instance where XML is
67
+
required. This is due to the limitations of the MyBatis annotations when mapping collections.
65
68
66
69
The library supports four join types:
67
70
@@ -74,14 +77,14 @@ The library supports four join types:
74
77
The library supports the generation of UNION and UNION ALL queries. For example:
@@ -114,7 +117,8 @@ paging clauses can be applied to the merged queries. For example:
114
117
## MyBatis Mapper for Select Statements
115
118
116
119
The SelectStatementProvider object can be used as a parameter to a MyBatis mapper method directly. If you
117
-
are using an annotated mapper, the select method should look like this (note that we recommend coding a "selectMany" and a "selectOne" method with a shared result mapping):
120
+
are using an annotated mapper, the select method should look like this (note that we recommend coding a "selectMany"
121
+
and a "selectOne" method with a shared result mapping):
If you are coding a join, it is likely you will need to code an XML mapper to define the result map. This is due to a MyBatis limitation - the annotations cannot define a collection mapping. If you have to do this, the Java code looks like this:
150
+
If you are coding a join, it is likely you will need to code an XML mapper to define the result map. This is due to a
151
+
MyBatis limitation - the annotations cannot define a collection mapping. If you have to do this, the Java code looks
@@ -171,7 +177,8 @@ And the corresponding XML looks like this:
171
177
Notice that the resultMap is the only element in the XML mapper. This is our recommended practice.
172
178
173
179
## XML Mapper for Select Statements
174
-
We do not recommend using an XML mapper for select statements, but if you want to do so the SelectStatementProvider object can be used as a parameter to a MyBatis mapper method directly.
180
+
We do not recommend using an XML mapper for select statements, but if you want to do so the SelectStatementProvider
181
+
object can be used as a parameter to a MyBatis mapper method directly.
175
182
176
183
If you are using an XML mapper, the select method should look like this in the Java interface:
177
184
@@ -205,30 +212,33 @@ Order by phrases can be difficult to calculate when there are aliased columns, a
205
212
This library has taken a relatively simple approach:
206
213
207
214
1. When specifying an SqlColumn in an ORDER BY phrase the library will either write the column alias or the column
208
-
name into the ORDER BY phrase. For the ORDER BY phrase, the table alias (if there is one) will be ignored. Use this pattern
209
-
when the ORDER BY column is a member of the select list. For example `orderBy(foo)`. If the column has an alias, then
210
-
it is easist to use the "arbitrary string" method with the column alias as shown below.
211
-
1. It is also possible to explicitly specify a table alias for a column in an ORDER BY phrase. Use this pattern when
212
-
there is a join, and the ORDER BY column is in two or more tables, and the ORDER BY column is not in the select
213
-
list. For example `orderBy(sortColumn("t1", foo))`.
214
-
1. If none of the above use cases meet your needs, then you can specify an arbitrary String to write into the rendered ORDER BY
215
-
phrase (see below for an example).
215
+
name into the ORDER BY phrase. For the ORDER BY phrase, the table alias (if there is one) will be ignored. Use this
216
+
pattern when the ORDER BY column is a member of the select list. For example `orderBy(foo)`. If the column has an
217
+
alias, then it is easiest to use the "arbitrary string" method with the column alias as shown below.
218
+
2. It is also possible to explicitly specify a table alias for a column in an ORDER BY phrase. Use this pattern when
219
+
there is a join, and the ORDER BY column is in two or more tables, and the ORDER BY column is not in the select
220
+
list. For example `orderBy(sortColumn("t1", foo))`.
221
+
3. If none of the above use cases meet your needs, then you can specify an arbitrary String to write into the rendered
222
+
ORDER BY phrase (see below for an example).
216
223
217
224
In our testing, this caused an issue in only one case. When there is an outer join and the select list contains
218
225
both the left and right join column. In that case, the workaround is to supply a column alias for both columns.
219
226
220
-
When using a column function (lower, upper, etc.), then it is customary to give the calculated column an alias so you will have a predictable result set. In cases like this there will not be a column to use for an alias. The library supports arbitrary values in an ORDER BY expression like this:
227
+
When using a column function (lower, upper, etc.), then it is customary to give the calculated column an alias so you
228
+
will have a predictable result set. In cases like this there will not be a column to use for an alias. The library
229
+
supports arbitrary values in an ORDER BY expression like this:
In this example the `substring` function is used in both the select list and the GROUP BY expression. In the ORDER BY expression, we use the `sortColumn` function to duplicate the alias given to the column in the select list.
240
+
In this example the `substring` function is used in both the select list and the GROUP BY expression. In the ORDER BY
241
+
expression, we use the `sortColumn` function to duplicate the alias given to the column in the select list.
232
242
233
243
## Limit and Offset Support
234
244
Since version 1.1.1 the select statement supports limit and offset for paging (or slicing) queries. You can specify:
@@ -237,18 +247,22 @@ Since version 1.1.1 the select statement supports limit and offset for paging (o
237
247
- Offset only
238
248
- Both limit and offset
239
249
240
-
It is important to note that the select renderer writes limit and offset clauses into the generated select statement as is. The library does not attempt to normalize those values for databases that don't support limit and offset directly. Therefore, it is very important for users to understand whether or not the target database supports limit and offset. If the target database does not support limit and offset, then it is likely that using this support will create SQL that has runtime errors.
250
+
It is important to note that the select renderer writes limit and offset clauses into the generated select statement as
251
+
is. The library does not attempt to normalize those values for databases that don't support limit and offset directly.
252
+
Therefore, it is very important for users to understand whether the target database supports limit and offset.
253
+
If the target database does not support limit and offset, then it is likely that using this support will create SQL
0 commit comments