I need to be able to dump a single object in the database during a larger Hibernate transaction.
I do not want to commit the transaction, since some of the entities attached to the transaction are incompatible and cannot be flushed to the database yet, but I need one object to be cleared, as later in the transaction, this object is included in the aggregate request to verify the transaction.
We have a quantitative position that needs to be saved in the database, as later (in the same transaction), we make a selection of the amount (quantity) from the same table, and the total quantity must meet certain criteria for the entire transaction really.
If the quantity is not saved, the amount (quantity) returns the wrong value, but if it is saved, the amount is correct and the rest of the transaction processing can be completed.
I also can’t “just add” the quantity from the position to the final result, since in fact there are many positions in different places, and the place where the sum is called is in another module to the fact that the element is added.
If I could just reset (SQL Insert) one position in the database in the current transaction, the system will work correctly.
Additional Information:
I found that I do not understand this problem on SQL Server, but am doing it in Oracle. It was weird ..
So, I hunted for it, and it seems that inside Hibernate, when you call saveOrUpdate, the system looks at how the @Id object is generated.
In SQL Server, we have an Identity column, and the only way to get its identifier is to be inserted (in the way that I want), while in ORACLE it does not support Identities, and therefore uses Sequence to generate the identifier of each column.
Due to the fact that ORACLE does not need to insert a record to create an identifier, the object is not inserted while it is on SQL Server.
Summary
So, it seems that Hibernate supports selective insertion, but so far it only inserts when IT is required, now I need to find if there is a way I can force it.