|
15 | 15 | */
|
16 | 16 | package org.springframework.data.jpa.provider;
|
17 | 17 |
|
18 |
| -import static org.springframework.data.jpa.provider.JpaClassUtils.isEntityManagerOfType; |
19 |
| -import static org.springframework.data.jpa.provider.JpaClassUtils.isMetamodelOfType; |
| 18 | +import static org.springframework.data.jpa.provider.JpaClassUtils.*; |
20 | 19 | import static org.springframework.data.jpa.provider.PersistenceProvider.Constants.*;
|
21 | 20 |
|
22 | 21 | import jakarta.persistence.EntityManager;
|
|
25 | 24 | import jakarta.persistence.metamodel.Metamodel;
|
26 | 25 | import jakarta.persistence.metamodel.SingularAttribute;
|
27 | 26 |
|
28 |
| -import java.util.*; |
| 27 | +import java.util.Collection; |
| 28 | +import java.util.Collections; |
| 29 | +import java.util.Date; |
| 30 | +import java.util.List; |
| 31 | +import java.util.NoSuchElementException; |
| 32 | +import java.util.Set; |
29 | 33 |
|
30 | 34 | import org.eclipse.persistence.config.QueryHints;
|
31 | 35 | import org.eclipse.persistence.jpa.JpaQuery;
|
32 | 36 | import org.eclipse.persistence.queries.ScrollableCursor;
|
33 | 37 | import org.hibernate.ScrollMode;
|
34 | 38 | import org.hibernate.ScrollableResults;
|
35 | 39 | import org.hibernate.proxy.HibernateProxy;
|
| 40 | +import org.hibernate.query.TypedParameterValue; |
36 | 41 | import org.springframework.data.jpa.repository.query.JpaParameters;
|
37 | 42 | import org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor;
|
38 | 43 | import org.springframework.data.util.CloseableIterator;
|
@@ -338,6 +343,27 @@ public static Object condense(Object value) {
|
338 | 343 | return value;
|
339 | 344 | }
|
340 | 345 |
|
| 346 | + /** |
| 347 | + * If Hibernate is on the classpath, potentially extract it's {@link TypedParameterValue}. |
| 348 | + * |
| 349 | + * @param extractedValue |
| 350 | + * @return either the {@link TypedParameterValue#getValue()} or the original value as a {@link Date}. |
| 351 | + * @since 3.1 |
| 352 | + */ |
| 353 | + public static Date extractDate(Object extractedValue) { |
| 354 | + |
| 355 | + ClassLoader classLoader = PersistenceProvider.class.getClassLoader(); |
| 356 | + |
| 357 | + if (ClassUtils.isPresent("org.hibernate.query.TypedParameterValue", classLoader)) { |
| 358 | + |
| 359 | + return (extractedValue instanceof TypedParameterValue<?> typedParameterValue) |
| 360 | + ? (Date) typedParameterValue.getValue() |
| 361 | + : (Date) extractedValue; |
| 362 | + } |
| 363 | + |
| 364 | + return (Date) extractedValue; |
| 365 | + } |
| 366 | + |
341 | 367 | /**
|
342 | 368 | * Holds the PersistenceProvider specific interface names.
|
343 | 369 | *
|
|
0 commit comments