openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henno Vermeulen <he...@huizemolenaar.nl>
Subject preventing N+1 select performance problem on maps
Date Wed, 19 Jan 2011 16:51:14 GMT
Sorry if this is a double post but I noticed I didn't really pose a question in my previous
mail from 2011-1-7.

When I have an entity that contains a Map, e.g.

@Entity
public class TestEntity {
@ElementCollection(fetch = FetchType.EAGER)
Map<String, String> strings = new HashMap<String, String>();
}

and I select multiple entities (SELECT z FROM TestEntity z), OpenJPA 2.0 performs one query
for each TestEntity to fetch the map. This also happens when the Map value is an entity and
I use @OneToMany instead of @ElementCollection. In principle this can be done more efficiently
with one query that selects all the map entries for all returned TestEntities. For Collection-valued
fields OpenJPA already does this by default (openjpa.jdbc.EagerFetchMode" value="parallel").

Could I be doing something wrong? Is there an easy way to tell OpenJPA to not perform a query
per entity but only one?
Or is there already any work planned on improving this (I filed it under https://issues.apache.org/jira/browse/OPENJPA-1920)?

It is a problem for us because we wish to fetch (and detach) a list of about 1900 products
which takes almost 15 seconds with OpenJPA. It takes less than a second with my own native
query.

Having to write only one native query wouldn't be much of a problem but the map we use is
inside a reusable StringI18N entity which is referenced from several different entities (and
can be deep in the object graph), so native queries are a maintenance headache.
Any help getting performance up is greatly appreciated.

Regards,
Henno Vermeulen
Huize Molenaar

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message