pefernan commented on code in PR #2298:
URL: 
https://github.com/apache/incubator-kie-kogito-apps/pull/2298#discussion_r2821474453


##########
data-audit/kogito-addons-data-audit-jpa/kogito-addons-data-audit-jpa-common/src/main/java/org/kie/kogito/app/audit/jpa/queries/mapper/PojoMapper.java:
##########
@@ -46,14 +51,60 @@ public PojoMapper(Class<T> clazz) {
     @Override
     public List<T> produce(List<Object[]> data) {
         List<T> transformed = new ArrayList<>();
+        Class<?>[] paramTypes = defaultConstructor.getParameterTypes();
         for (Object[] row : data) {
             try {
-                transformed.add(defaultConstructor.newInstance(row));
+                // Hibernate 7 changed default return types for native queries
+                // (e.g. OffsetDateTime instead of java.util.Date, Long 
instead of Integer).
+                // Convert each value to match the constructor's declared 
parameter types.
+                Object[] convertedRow = convertTypes(row, paramTypes);
+                transformed.add(defaultConstructor.newInstance(convertedRow));
             } catch (InstantiationException | IllegalAccessException | 
IllegalArgumentException | InvocationTargetException e) {
                 LOGGER.error("Could not transform data", e);
             }
         }
         return transformed;
     }
 
+    private static Object[] convertTypes(Object[] row, Class<?>[] paramTypes) {
+        Object[] result = new Object[row.length];
+        for (int i = 0; i < row.length; i++) {
+            result[i] = (i < paramTypes.length) ? convertValue(row[i], 
paramTypes[i]) : row[i];
+        }
+        return result;
+    }
+
+    private static Object convertValue(Object value, Class<?> targetType) {
+        if (value == null || targetType.isInstance(value)) {
+            return value;
+        }
+        // Hibernate 7 returns java.time types instead of java.util.Date
+        if (targetType == Date.class) {
+            if (value instanceof OffsetDateTime) {
+                return Date.from(((OffsetDateTime) value).toInstant());
+            }
+            if (value instanceof Instant) {
+                return Date.from((Instant) value);
+            }
+            if (value instanceof LocalDateTime) {
+                return Date.from(((LocalDateTime) 
value).atZone(ZoneId.of("UTC")).toInstant());
+            }
+        }
+        // Hibernate 7 may return different numeric types for native query 
columns
+        if (targetType == Integer.class || targetType == int.class) {
+            if (value instanceof Number) {
+                return ((Number) value).intValue();
+            }
+        }
+        if (targetType == Long.class || targetType == long.class) {
+            if (value instanceof Number) {
+                return ((Number) value).longValue();
+            }
+        }
+        if (targetType == String.class) {
+            return value.toString();

Review Comment:
   @jeejz is this really needed? is Hibernate wrapping strings values in a 
custom type?



##########
data-audit/kogito-addons-data-audit-jpa/kogito-addons-data-audit-jpa-common/src/main/java/org/kie/kogito/app/audit/jpa/queries/JPADynamicQuery.java:
##########
@@ -112,7 +110,9 @@ private Object transform(GraphQLOutputType outputType, 
Object source) {
         if (outputType instanceof GraphQLScalarType) {
             GraphQLScalarType scalarType = (GraphQLScalarType) outputType;
             if ("DateTime".equals(scalarType.getName())) {
-                target = OffsetDateTime.ofInstant(((Timestamp) 
source).toInstant(), ZoneId.of("UTC"));
+                // Hibernate 7 returns OffsetDateTime directly for temporal 
columns in native queries,
+                // not java.sql.Timestamp as in Hibernate 5/6. Use 
DateTimeUtil for cross-version compatibility.
+                target = DateTimeUtil.toDateTime(source);

Review Comment:
   maybe use static import directly here.



##########
data-index/data-index-springboot/kogito-addons-springboot-data-index-persistence/kogito-addons-springboot-data-index-persistence-jpa-parent/integration-tests-process/src/main/resources/application.properties:
##########
@@ -24,5 +24,4 @@ kogito.persistence.type=jdbc
 kie.flyway.enabled=true
 
 # Disabling Spring-Boot Flyway to avoid unnecessary Data Base initialization
-spring.flyway.enabled=false
-
+spring.flyway.enabled=false

Review Comment:
   Unnecessary change?



##########
jobs/kogito-addons-springboot-embedded-jobs/src/main/java/org/kie/kogito/app/jobs/springboot/SpringbootJobServiceConfiguration.java:
##########
@@ -39,6 +39,11 @@
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 
+// Note: The Hibernate 7 + Spring ORM 6.2 EntityManagerFactory workaround 
(BeanPostProcessor for
+// setEntityManagerFactoryInterface) is intentionally NOT in this class. This 
module does not have

Review Comment:
   Maybe we don't need this comment



##########
jobs/kogito-addons-embedded-jobs-jpa/kogito-addons-springboot-embedded-jobs-jpa/src/main/java/org/kie/kogito/app/jobs/springboot/jpa/SpringbootJPAJobStoreConfiguration.java:
##########
@@ -29,4 +32,20 @@
 @EnableAutoConfiguration
 public class SpringbootJPAJobStoreConfiguration {
 
+    // Hibernate 7 + Spring ORM 6.2 workaround: Hibernate 7's 
SessionFactory.getSchemaManager()
+    // returns org.hibernate.relational.SchemaManager, conflicting with JPA 
3.2's
+    // EntityManagerFactory.getSchemaManager() returning 
jakarta.persistence.SchemaManager.
+    // Force plain JPA interface to avoid JDK Proxy incompatible return type 
error.
+    @Bean
+    public static BeanPostProcessor 
entityManagerFactoryInterfacePostProcessor() {

Review Comment:
   I have same doubt here than with data audit. I need to test this one



##########
data-audit/kogito-addons-data-audit-jpa/kogito-addons-data-audit-jpa-common/src/main/java/org/kie/kogito/app/audit/jpa/queries/JPADynamicQuery.java:
##########
@@ -112,7 +110,9 @@ private Object transform(GraphQLOutputType outputType, 
Object source) {
         if (outputType instanceof GraphQLScalarType) {
             GraphQLScalarType scalarType = (GraphQLScalarType) outputType;
             if ("DateTime".equals(scalarType.getName())) {
-                target = OffsetDateTime.ofInstant(((Timestamp) 
source).toInstant(), ZoneId.of("UTC"));
+                // Hibernate 7 returns OffsetDateTime directly for temporal 
columns in native queries,

Review Comment:
   No need for this comment. 
   



##########
jobs-service/jobs-service-storage-jpa/src/main/java/org/kie/kogito/jobs/service/repository/jpa/model/JobDetailsEntity.java:
##########
@@ -25,6 +25,8 @@
 import com.fasterxml.jackson.databind.node.ObjectNode;
 
 import jakarta.persistence.*;
+import jakarta.persistence.Temporal;

Review Comment:
   Are this imports needed? (import jakarta.persistence.*;)



##########
jobs-service/jobs-service-storage-jpa/src/main/java/org/kie/kogito/jobs/service/repository/jpa/model/JobDetailsEntity.java:
##########


Review Comment:
   based on 
https://github.com/apache/incubator-kie-kogito-apps/pull/2298/changes#r2821614790
   
   this could be removed as  well right?



##########
data-audit/kogito-addons-data-audit-springboot/src/main/java/org/kie/kogito/app/audit/springboot/SpringbootAuditDataConfiguration.java:
##########
@@ -18,13 +18,32 @@
  */
 package org.kie.kogito.app.audit.springboot;
 
+import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.boot.SpringBootConfiguration;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
 
 @SpringBootConfiguration
 @EnableAutoConfiguration
 @ComponentScan
 public class SpringbootAuditDataConfiguration {
 
+    // Hibernate 7 + Spring ORM 6.2 workaround: Hibernate 7's 
SessionFactory.getSchemaManager()
+    // returns org.hibernate.relational.SchemaManager, conflicting with JPA 
3.2's
+    // EntityManagerFactory.getSchemaManager() returning 
jakarta.persistence.SchemaManager.
+    // Force plain JPA interface to avoid JDK Proxy incompatible return type 
error.
+    @Bean
+    public static BeanPostProcessor 
entityManagerFactoryInterfacePostProcessor() {
+        return new BeanPostProcessor() {
+            @Override
+            public Object postProcessBeforeInitialization(Object bean, String 
beanName) {
+                if (bean instanceof LocalContainerEntityManagerFactoryBean 
emfb) {

Review Comment:
   @jeejz do you know why this is a problem in Data Audit but not in other 
components like usertasks storage or data index?



##########
jobs-service/jobs-service-storage-jpa/src/main/java/org/kie/kogito/jobs/service/repository/jpa/model/JobServiceManagementEntity.java:
##########
@@ -35,7 +35,7 @@ public class JobServiceManagementEntity {
     private String id;
 
     @Column(name = "last_heartbeat")
-    @Temporal(TemporalType.TIMESTAMP)
+    // @Temporal not needed for OffsetDateTime in Hibernate 7 / JPA 3.2

Review Comment:
   If this is true we can remove this line



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to