Uploaded image for project: 'Hibernate ORM'
  1. Hibernate ORM
  2. HHH-8487

Auto-flush on JPA native SQL query

    Details

    • Last commented by a user?:
      true

      Description

      We will need to make a slight change to execution of JPA native SQL queries to add an "auto flush".

      The problem with this is that, unlike with HQL/JPQL, we do not know the tables affected by a native SQL query (and doing so would be extremely difficult and not worth the effort). Historically, Hibernate users would have relied on the addSynchronizedQuerySpace/addSynchronizedEntityName methods of org.hibernate.SQLQuery to indicate the tables needing flushed. JPA however has no such notion.

      As I see it, I think the change here needs to be to implicitly perform a full flush when a JPA native SQL query is executed where the wrapped/underlying org.hibernate.SQLQuery does not define any "query spaces"; a partial flush just is not possible in that case. That allows us to pass the TCK, but still allows users to set "query spaces" if they wish to do the more efficient partial auto-flush.


      For posterity, HEM users can still accomplish this by unwrapping to Hibernate's native org.hibernate.SQLQuery adding to the "synchronized query spaces", like:

      Query jpaSqlQuery = entityManager.createNativeQuery( ... );
      jpaSqlQuery.unwrap( org.hibernate.SQLQuery.class ).addSynchronizedEntityClass( Person.class );
      ...
      

      There are 3 forms of adding "synchronized query spaces":

      • addSynchronizedQuerySpace - Add a table to synchronize on
      • addSynchronizedEntityClass - Add the tables to which the given entity (by class) is mapped
      • addSynchronizedEntityName - Add the tables to which the given entity (by name) is mapped

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            brmeyer Brett Meyer added a comment -

            Bulk closing tickets resolved in released versions

            Show
            brmeyer Brett Meyer added a comment - Bulk closing tickets resolved in released versions
            Hide
            mih_vlad Mihalcea Vlad added a comment -

            I tested this with the 4.3.5 version an SQL queries don't force a flush before execution.

            Check the unit test I attached on this issue: https://hibernate.atlassian.net/browse/HHH-9315

            Show
            mih_vlad Mihalcea Vlad added a comment - I tested this with the 4.3.5 version an SQL queries don't force a flush before execution. Check the unit test I attached on this issue: https://hibernate.atlassian.net/browse/HHH-9315

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - Not Specified
                  Not Specified
                  Logged:
                  Time Spent - 0.85h
                  0.85h

                    Development