Home > database >  Using MariaDB temporal tables with spring data jpa native query is not giving me the correct result
Using MariaDB temporal tables with spring data jpa native query is not giving me the correct result

Time:02-14

public interface PeseeRepository extends JpaRepository<Pesee, Integer> {
...
    @Query(value = "SELECT * FROM pesee FOR SYSTEM_TIME all WHERE id_pesage = ?1", nativeQuery = true)
    List<Pesee> findAllPeseeHystoryById(Integer id);
...
}

Log:

Hibernate: 
SELECT
    * 
FROM
    pesee FOR SYSTEM_TIME all 
WHERE
    id_pesage = ?

result of the native query in my program : enter image description here

raw sql exemple:

    SELECT
    * 
FROM
    pesee FOR SYSTEM_TIME all 
WHERE
    id_pesage = 1879;

result in raw sql:

enter image description here

apparently the native jpa query does not return the same result as the standard sql query.

But detects the number of rows correctly.

Here is my question: How to make mariadb table versioning work in my spring boot application? The goal is simply to return me history of a table.

CodePudding user response:

I found how to solve my problem by going through a lower level query

enter image description here

For the Objects to recover I called on my service in PeseeJDBC and I transmitted it to PeseeMapper Then in the PeseeMapper class I called findById from my transmitted service. (I did not add this in the example codes so as not to complicate the initial problem) It's a bit wobbly at the architectural level but it's functional

  • Related