[hibernate-issues] [Hibernate-JIRA] Created: (HHH-6814) Adding item to persistent set causes hibernate to individually load each set item
Tim Heys (JIRA)
noreply at atlassian.com
Wed Nov 9 12:54:22 EST 2011
Adding item to persistent set causes hibernate to individually load each set item
---------------------------------------------------------------------------------
Key: HHH-6814
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6814
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.7
Environment: Hibernate 3.6.7 Core with PostrgreSQL 8.2.18
Reporter: Tim Heys
When adding an item to a Persistent Set hibernate loads each item of the set individually even if the set has already been loaded.
My code:
@OneToMany(fetch = FetchType.LAZY,
targetEntity = Item.class,
mappedBy = "parent",
cascade = CascadeType.ALL,
orphanRemoval = true)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@BatchSize(size = 20)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@IndexedEmbedded(prefix = "item")
@Valid
public Set<Item> getItems() {
return items;
}
Calling "obj.getItems().add(newItem);", Hibernate loads EVERY item in the Set with it's own query:
select
eitem0_.id as id5_0_,
eitem0_.parent_id as parent_id5_0_,
eitem0_.field1 as field13_5_0_,
eitem0_.field2 as field24_5_0_,
eitem0_.field3 as field35 as_5_0_
from
items eitem0_
where
eitem0_.id=?
I suppose it gets the IDs from the previous query when it loaded all the items:
select
eitem0_.parent_id as parent4_3_1_,
eitem0_.id as id1_,
eitem0_.id as id5_0_,
eitem0_.field1 as field15_0_,
eitem0_.field2 as field23_5_0_,
eitem0_.parent_id as parent4_5_0_,
eitem0_.field3 as field35_5_0_
from
items eitem0_
where
eitem0_.parent_id=?
This makes for a very inefficient add to Set operation.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list