| I have been carrying out an upgrade on a hibernate 4.1.1 application taking it up to 5.3.6. Some of the applications unit tests are failing and upon investigating, I am seeing unexpected behavior relating to the flushing of queries. The tests involve an inheritance model - an abstract base class and a child class. The JPA inheritance type is Inheritance.Joined. The test uses a JPA query that will match an attribute on the base class or on the child class. The test goes like this Begin transaction Create a child entity that will match the query on the base class. Execute the query and confirm 1 record is returned (this works on hibernate 4.1.1 and 5.3.6) Create a second child entity that will match the query on the child class Execute the query and confirm that 2 records are returned (this works on hibernate 4.1.1 and fails on hibernate 5.3.6) End Transaction Tracing the SQL being executed against the database I see the following: Insert into base table Select Insert into child table Insert into base table Select Insert into child table So the reason that the test is failing appears to be because the insert into the child table is happening after the select statement so the select doesn't match it. My understanding is that all inserts should be executed prior to a select but this doesn't appear to be the case for the child table i.e. the entity has only partially been inserted before the select query is executed. I tried adding a manual em flush prior to executing the query and this had no effect. I have looked for hibernate properties that might influence this behavior and not been successful hence reporting this as a bug. |