Bidirectional OneToMany is slow on updated items

#1

Hello,

I have a problem with the following situation. I insert persons with addresses.

In the first run, they are all new with a new address. It runs fast.

In the second run, the persons are all loaded and got a second address. This seams to be much slower.

The Entities are all enhanced by the javaagent (which you can see in the contained eclipse launch configuration)

Is there any way to speed it up?

 

 

 

#2

Your test becomes slow as the database is filled.

Every task run includes:

  • Execution of 10,000 find requests of Person instances.
  • Execution of 10,000 find requests of Address instances.
  • For existing persons - retrieval of the addressSet, which is a mapped by (inverse) collection, and therefore requires a costly query execution

You start feeling the cost of these operations, and mainly the addressSet retrieval when the database is not empty.

A simple action that can improve performance dramatically, is to avoid using mapped by collections:

@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY/*, mappedBy = "person"*/)
private Set<Address> addressSet = new HashSet<Address>();

After converting this mapped by collection to an ordinary collection, the results are:

..................................................2590
..................................................1573
..................................................627

i.e. the 2nd and 3rd runs are faster than the 1st.

If you need to improve performance further, consider replacing the find calls of Address and Person instances with an in memory HashMap and get calls.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

Thanks for the reply. This looks great.

 

But without the mappedby, there are to independent relations. One from Person to Address and the other from Address to Person. This means I had to manage both by myself?

Wenn filling a relational database this leads in two foreign keys, or not?

Is there a way, not to change the code. Instead set a property to force objectdb to handle all mappedby as ordinary collections?

#4

Yes, with this solution you will have to maintain two unidirectional relationships.

As your request, a new system property was added in ObjectDB 2.4.7 to disable mappedBy relationships. Try:

> java -Dobjectdb.temp.no-mapped-by=true ...

or 

System.setProperty("objectdb.temp.no-mapped-by", "true");

 

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#5

Sorry for the late answer. Thanks the key works like intended.


Post Reply

To post a reply and/or subscribe to update notifications - please login