|
15 | 15 | */
|
16 | 16 | package org.springframework.data.jpa.repository.query;
|
17 | 17 |
|
18 |
| -import static org.assertj.core.api.Assertions.*; |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
| 20 | +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; |
| 21 | +import static org.assertj.core.api.Assertions.assertThatNullPointerException; |
19 | 22 |
|
20 | 23 | import jakarta.persistence.EntityManager;
|
21 | 24 | import jakarta.persistence.PersistenceContext;
|
|
27 | 30 |
|
28 | 31 | import java.util.Locale;
|
29 | 32 |
|
| 33 | +import org.hibernate.query.sqm.tree.SqmRenderContext; |
30 | 34 | import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
|
31 | 35 | import org.junit.jupiter.api.Disabled;
|
32 | 36 | import org.junit.jupiter.api.Test;
|
33 | 37 | import org.junit.jupiter.api.extension.ExtendWith;
|
34 |
| - |
35 | 38 | import org.springframework.data.jpa.domain.JpaSort;
|
36 | 39 | import org.springframework.data.jpa.domain.sample.User;
|
37 | 40 | import org.springframework.test.context.ContextConfiguration;
|
@@ -125,26 +128,26 @@ void temporalLiterals() {
|
125 | 128 |
|
126 | 129 | // JDBC
|
127 | 130 | assertThat(renderOrderBy(JpaSort.unsafe("createdAt + {ts '2024-01-01 12:34:56'}"), "u"))
|
128 |
| - .startsWithIgnoringCase("order by u.createdAt + 2024-01-01T12:34:56"); |
| 131 | + .startsWithIgnoringCase("order by u.createdAt + '2024-01-01T12:34:56'"); |
129 | 132 |
|
130 | 133 | assertThat(renderOrderBy(JpaSort.unsafe("createdAt + {ts '2012-01-03 09:00:00.000000001'}"), "u"))
|
131 |
| - .startsWithIgnoringCase("order by u.createdAt + 2012-01-03T09:00:00.000000001"); |
| 134 | + .startsWithIgnoringCase("order by u.createdAt + '2012-01-03T09:00:00.000000001'"); |
132 | 135 |
|
133 | 136 | // Hibernate NPE
|
134 |
| - assertThatNullPointerException().isThrownBy(() -> renderOrderBy(JpaSort.unsafe("createdAt + {t '12:34:56'}"), "u")); |
| 137 | + assertThatIllegalArgumentException().isThrownBy(() -> renderOrderBy(JpaSort.unsafe("createdAt + {t '12:34:56'}"), "u")); |
135 | 138 |
|
136 | 139 | assertThat(renderOrderBy(JpaSort.unsafe("createdAt + {d '2024-01-01'}"), "u"))
|
137 |
| - .startsWithIgnoringCase("order by u.createdAt + 2024-01-01"); |
| 140 | + .startsWithIgnoringCase("order by u.createdAt + '2024-01-01'"); |
138 | 141 |
|
139 | 142 | // JPQL
|
140 | 143 | assertThat(renderOrderBy(JpaSort.unsafe("createdAt + {ts 2024-01-01 12:34:56}"), "u"))
|
141 |
| - .startsWithIgnoringCase("order by u.createdAt + 2024-01-01T12:34:56"); |
| 144 | + .startsWithIgnoringCase("order by u.createdAt + '2024-01-01T12:34:56'"); |
142 | 145 |
|
143 | 146 | assertThat(renderOrderBy(JpaSort.unsafe("createdAt + {t 12:34:56}"), "u"))
|
144 |
| - .startsWithIgnoringCase("order by u.createdAt + 12:34:56"); |
| 147 | + .startsWithIgnoringCase("order by u.createdAt + '12:34:56'"); |
145 | 148 |
|
146 | 149 | assertThat(renderOrderBy(JpaSort.unsafe("createdAt + {d 2024-01-01}"), "u"))
|
147 |
| - .startsWithIgnoringCase("order by u.createdAt + 2024-01-01"); |
| 150 | + .startsWithIgnoringCase("order by u.createdAt + '2024-01-01'"); |
148 | 151 | }
|
149 | 152 |
|
150 | 153 | @Test // GH-3172
|
@@ -262,7 +265,7 @@ String renderQuery(JpaSort sort, String alias) {
|
262 | 265 | SqmSelectStatement s = (SqmSelectStatement) q;
|
263 | 266 |
|
264 | 267 | StringBuilder builder = new StringBuilder();
|
265 |
| - s.appendHqlString(builder); |
| 268 | + s.appendHqlString(builder, SqmRenderContext.simpleContext()); |
266 | 269 |
|
267 | 270 | return builder.toString();
|
268 | 271 | }
|
|
0 commit comments