Hello, If you look at the documentation here : https://docs.jboss.org/hibernate/orm/6.1/userguide/html_single/Hibernate_User_Guide.html#_auto_flush_on_native_sql_query it says that it will flush the session if you use the entityManager to create the query. If you use the session to create the query it will not flush. In your test you use the session instead of the entityManager to create the query. That’s why it’s not flushing in hibernate 5. If you use the entityManager it would flush. Thank you Extracted from the link above : When executing a native SQL query, a flush is always triggered when using the EntityManager API. Example 414. Automatic flushing on native SQL using EntityManager
If you bootstrap Hibernate natively, and not through Jakarta Persistence, by default, the Session API will trigger a flush automatically when executing a native query. Example 415. Automatic flushing on native SQL using Session
To flush the Session, the query must use a synchronization: Example 416. Automatic flushing on native SQL with Session synchronization
|