Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to flush a single entity in a hibernate session
    text
    copied!<p>I need to be able to flush a single entity to the DB during a larger Hibernate transaction.</p> <p>I don't want to commit the transaction as some of the entities attached to the transaction are inconsistent and can't be flushed to the DB yet, but I need one entity to be flushed as later in the transaction this entity is included in an aggregate query to validate the transaction.</p> <p>We have a quantity line item that needs to be saved to the DB as later (in the same transaction) we doe a select sum(quantity) from the same table and the resultant quantity must match a certain criteria for the entire transaction is valid.</p> <p>If the quantity is not saved, the sum(quantity) returns the wrong value, but if it is saved then the sum is correct and the rest of the transaction processing can be completed.</p> <p>I also can't "just add" the quantity from the line item to the sum result as there are actually many line items all in different places and the place the sum is invoked is in a different module to the one that the item is added.</p> <p>If I could just flush (SQL Insert) the single line item to the DB within the current transaction, the system would work correctly.</p> <p><strong>More Info:</strong></p> <p>I have found that I don't get this problem on SQL Server, but do on Oracle. This was wierd..</p> <p>So I hunted into it, and it seems that inside Hibernate when you call "saveOrUpdate" the system looks to see how the @Id of the entity is generated.</p> <p>In SQL Server we have an Identity column, and the only way for the entity to get its ID is to be inserted (thus what I want), while in ORACLE it doesn't support Identities, and so uses a Sequence to generate the ID's of each column.</p> <p>Due to the fact that ORACLE doesn't need to insert the record to generate the ID means the entity is not inserted, while it is on SQL Server.</p> <p><strong>Summary</strong></p> <p>So it seems that Hibernate does support selective insertion, but so far it only inserts when IT needs to, now I need to find if there is a way I can force it to.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload