Add hibernate support for printing Specification/TypedQuery to string (for debug purposes) (#2213)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-21 15:50:26 +02:00
committed by GitHub
parent d93a73e2ab
commit e8406afeba
4 changed files with 146 additions and 36 deletions

View File

@@ -0,0 +1,29 @@
/**
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.repository.jpa;
import jakarta.persistence.TypedQuery;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.eclipse.persistence.jpa.JpaQuery;
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
@Slf4j
public class Utils {
public static String toSql(final TypedQuery<?> typedQuery) {
typedQuery.setParameter(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, "DEFAULT");
// executes the query - otherwise the SQL string is not generated
typedQuery.getResultList();
return typedQuery.unwrap(JpaQuery.class).getDatabaseQuery().getSQLString();
}
}