Home » Support » Forum » Apparent Lazy Loading issues.

Apparent Lazy Loading issues.



Thanks for the quick investigation. That has indeed fixed that issue. However there appear to be two more.

First, as we are dealing with maps, the "equals" and "hashcode" methods on the key object have to be overridden, so that "containsKey" and "get" methods work correctly. The issue with this is, when "find" is called, the object is being lazy loaded. So if the "equals" or "hashcode" method use more than the database id for generation or comparison, it all fails horribly. Have a look at the output from the second junit test, you will see heaps of calls like:

AttributeName EQUALS method called for <attributename name="null" values="" id="11"/> against: <attributename name="null" values="" id="10"/>

where the equals method has been called, but the attributename appears to have been lazy loaded.

For the purposes of continuing, I have set my "equals" method in attribute name to look only at the database id.

Second issue. The docs at: http://www.objectdb.com/api/java/jpa/OneToMany state: "When the collection is a java.util.Map, the cascade element and the orphanRemoval element apply to the map value." This appears to mean that if I have cascade=CascadeType.ALL on a OneToMany map, then the cascade ONLY applies to the values, NOT to the key. This means all keys MUST be created prior to trying to persist the map.

So I set the annotation on Holder.java at line 92 to have CascadeType.ALL. The test created the AttributeNames via the dao prior to trying to persist. The list of OtherObject is NOT persisted prior to the call. When I call persist, it fails with exception about trying to reuse a primary key for AttributeName. So I removed the CascadeType.All from Holder and persisted the OtherObjects prior to calling update on Holder and then it all works. However that then means any sub parts of OtherObjects (ie the Map<string,String>) don't get updated when they are changed (this is what the unit test is setup testing at the mo).

To reproduce the error, try replacing the annotation at line 92 in Holder.java, and removing the persisting of OtherObject in the unit test (lines 136-139 for ExampleTest.java).

I have attached the updated Maven project. Please let me know if I have missed something, or miss read the docs




The first problem is now described as issue #618. A fix will not be available immediately.

It is unclear if the second problem is one problem of two problems (since your project demonstrates one issue and in addition you provided instructions to change your code to see another issue).

Please use issue #618 as an example of how you should report issues.

Isolate the remaining problems (one or two). Describe each problem precisely in a separate thread with a focused descriptive title (the current subject, "Apparent Lazy Loading issues" is too wide, and indicates a post that doesn't follow the posting rules), and provide a simple test case. Please don't use a Spring based test case with DAO objects etc. instead of the required simple test case (as demonstrated in issue #118).

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

Post Reply

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