In the hibernate HBM file, what is the purpose of setting the following properties?
update = "false"
insert = "false"
What purpose do they serve? What difference do they make to the performance? When should we use them?
Use update="false", insert="false" when the property is calculated/derived, or when the database or triggers are responsible for inserting/ or updating the value.
For example, if the DB would automatically generate a value on INSERT that you want to use, then specify insert="false" so Hibernate won't include the property in INSERT statements.
Another example, would be a calculated/derived property via SQL formula: You could, for example, retrieve a sum of order-totals for each customer. Eg:
<property name="totalOrders" insert="false" update="false">
<formula>(select sum(ORDER.TOTAL) from ORDER where ORDER.FK_CUSTOMER=ID)</formula>
</property>
In this case we set insert="false", update="false" since this is clearly a derived result, and we can't update it directly.
Performance? It's not about performance -- it's about what your database mapping requires.
From the documentation:
update, insert (optional - defaults to true): specifies that the mapped columns should be included in SQL UPDATE and/or INSERT statements. Setting both to false allows a pure "derived" property whose value is initialized from some other property that maps to the same column(s), or by a trigger or other application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With