I have a spring data jpa app with Hibernate/Hikari/Hazelcast. The setup is similar to this demo project . The issue I am experiencing in my production code is that when a JpaRepository.save
is invoked I get an insert and then an update on the same entity. What I mean is, when we call
parents.save(parent)
Where parents
is a repository instance, the generated queries are :
insert into child(id, name, parent_id) values (?,?,?)
and immediately after
update child set name=? parent_id=? where id=?
,
I fail to see why this is happening. We will be saving around a thousand or more entities at a time and I am trying to minimize the unnecessary DB queries.
I would love it if someone can help out with some ideas why such a behavior is observed. The demo project resembles the actual setup in terms of entity relations, mappings and transactions. open-in-view
is set to false, no explicit @Transactional
annotations are used.
The problematic behavior is not observed in the demo project. I can't unfortunately share the production code here.
Thanks,