-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to save objects without first retrieving it
PostPosted: Thu Jun 18, 2009 5:04 pm 
Newbie

Joined: Thu Jun 18, 2009 4:34 pm
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.