-->
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.  [ 2 posts ] 
Author Message
 Post subject: performance issue in one-to-many
PostPosted: Mon Mar 22, 2010 6:35 pm 
Newbie

Joined: Mon Jul 09, 2007 9:32 am
Posts: 17
what is the best way to insert an object in one-to-many ?

for example, one Employee has many Task.

Code:
Employee{
  List<Task> taskList;
}


when we add one Task into Employee taskList, we have to load employee and its ALL task, and then save

Code:
function save_one_task(new_task){
  Employee employee = dao.load(...);
  List<Task> taskList = dao.loadAllTask(); // line 2

  taskList.add(new_task);

  employee.setTaskList(taskList);

  dao.save(employee);
}

The major performance issue is line 2. we need to load ALL task, maybe 1000, just for adding ONE task.

Do we have a better way to resolve this issue ?

Thanks.


Top
 Profile  
 
 Post subject: Re: performance issue in one-to-many
PostPosted: Tue Mar 23, 2010 2:54 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
One possibility is to let the Task be the owner of the relation. Then you can simply do:


Code:
function save_one_task(new_task){
  Employee employee = dao.load(...);
  new_task.setEmployee(employee);
}


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

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.