Issue Details (XML | Word | Printable)

Key: BSHD-8
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Gabriele Catania
Reporter: Scott Rainaldo
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Base spring/hibernate DAO

OutOfMemoryError on findFiltered( ) with bi-directional one-to-many relationship

Created: 28/Jul/10 22:48   Updated: 25/Aug/10 08:13   Resolved: 25/Aug/10 08:08
Component/s: None
Affects Version/s: 2.0.5
Fix Version/s: 2.1.0

File Attachments: 1. Text File StackTrace.txt (3 kB) 28/Jul/10 22:48 - Scott Rainaldo

Environment: Windows XP, Eclipse 3.5, Java 6 JRE


 Description  « Hide

I am getting an OutOfMemoryError upon executing a findFiltered( ) query with a bi-directional one-to-many Hibernate relationship. The stack trace is attached. It seems the code is in an infinite loop due to the circular references.

Here is an example of the relationship:

class Parent { private Long id; private Set<Child> children; ... other fields and code }

class Child { private Long id; private Parent parent; // needed for foreign key relationship ... other fields and code }

Test code:

public Parent findByChildren(Set<Child> children)

{ Parent parent = new Parent(); parent.setChildren(children); bshd5DAO.findFiltered(parent); // OutOfMemoryError here }

Gabriele Catania added a comment - 24/Aug/10 22:24 - edited

This is a known issue in the current EnhancedExample implementation. What happens in your case is:

  1. when the parent object is processed, each of its writeable properties (identified by the presence of setter methods) are examined
  2. each property whose type is non-trivial (i.e. not one of string, simple type) and value is non-null (or not empty in case of collections) is processed recursively. In your case, the children property of type Set<Child> is found with a non-empty value and processed
  3. each property of the child object is examined: a parent property of nontrivial type is found and processed, so we're back to step one.

I am afraid with the current implementation, you need to adopt one of the following workarounds:

  • rename the setter method of the parent property of Child to a nonstandard name (e.g. updateParent()) so that it is not recognized as a writeable property by the recursive method
  • remove the setter method on the parent property of Child altogheter

This is one of the limitations of the current implementation and will be resolved on the next release.