I am having performance problems with my code, when trying to update a lot of records at once.
How to avoid retrieving the object if I want simply update it? Simple code Data data = myService.getData(dataId); data.setSomething(something); myService.save(data);
may produce unnecessary SELECT statements, when I need only one UPDATE statement.
I am running complex algorithms that basically generate clusters of data. Each piece of data then is supposed to updated with a cluster that it belongs to. Algorithm returns list of clusters, and each clusters has list of data ids, that belong to cluster. To update this data I use:
for(Long dataId : dataList) { Data data = myService.getData(dataId); data.setCluster(cluster); myService.save(data); }
Each iteration produce sth like this:
Hibernate: select need0_.id as id0_0_, need0_.created as created0_0_, ............... Hibernate: select cluster0_.id as id3_0_, cluster0_.created ............ Hibernate: select user0_.id as id1_0_, user0_.created as created1_0_, ............. Hibernate: select project0_.id as id5_0_, project0_.created .............. Hibernate: select joinedproj0_.user_id as user7_2_, joinedproj0_.id ......... Hibernate: update Need set updated=?, cluster_id=?, creator_id=?, project_id=?, score=?, text=? where id=?
I don't need all these SELECT's. I only want to do UPDATE per iteration. Imagine if I have 1000 iterations. Please help... I might still not understand some issues about hibernate, as I am new to it. If you need more details about the code let me know...
Thank you
|