I am wondering how to reduce SQL updates using the settings of Hibernate (4) and Oracle.
A simple case might be the following:
Open a session / transaction, create a new Xyz object with session.save (), process some business logic, make some changes to Xyz and call session.update () and let the session be closed as usual and Hibernate with commit to DB .
When the transaction is completed, Hibernate will perform an insert followed by an update - but in this example, all she really needs to do is the only insert, but with the latest Xyz properties.
Does anyone have any ideas / templates for this kind of thing? Or is there a way to change the behavior of Hibernate? Or is your opinion on this a complete anti-pattern?
I know that Hibernate is smart enough to omit multiple updates when one update simply overwrites another - so why doesn't it look like an insert?
This small snippet can reproduce the “question”:
MyEntity e = new MyEntity("xxx"); Session session = sessionFactory.openSession(); session.beginTransaction(); session.save(e); e.setName("yyy"); session.getTransaction().commit(); session.close();
By the way, I have no triggers to worry about.
This example is very simple, and the performance problem may seem trivial, but in fact I am dealing with a more complex object (i.e. several inserts and updates) and large volumes, so avoiding the updates would be great.
source share