Wednesday, November 28, 2012

ValueProxy and cyclic dependencies lead to infinite loop

I am not sure if this is a known issue. But I recently tried to map some JPA2 Entities to ValueProxy's and run into a weird issue.

In the database I have a table (Term) which references itself using an intermediate/mapping table (basically building a graph like structure).

Term ---> Term2Term.parent
Term <--- Term2Term.child

Basically a record from table A can have n childrin and exactly one parent (DAG).

The ValueProxy's look like this:

  @ProxyForName(value="xxxxx")  public interface TermProxy extends ValueProxy {      public Integer getId();      ......      public Set<Term2TermProxy> getParents();      public Set<Term2TermProxy> getChilds();  }
  @ProxyForName(value="xxxx")  public interface Term2TermProxy extends ValueProxy {        public Integer getId();      public TermProxy getParent();        public TermProxy getChild();    }

Furthermore I have an EntityProxy in which one Term is embedded:

  @ProxyForName(xxx)  public interface SomeEntityProxy extends EntityProxy{      TermProxy getTraitOntologyTerm();    }

When I load the SomeEntityProxy object and also load the TermProxy I run into an infinite loop on the backend/server when serializing the payload with following exception:

java.lang.reflect.UndeclaredThrowableException      at $Proxy118.hashCode(Unknown Source)      at      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(      at sun.reflect.DelegatingMethodAccessorImpl.invoke(      at java.lang.reflect.Method.invoke(      at      at $Proxy118.hashCode(Unknown Source)      at java.util.HashMap.hash(      at java.util.HashMap.put(      at java.util.HashSet.add(      at      at$400(      at$PropertyResolver.visitReferenceProperty(      at      at      at      at      at

I suspect that this is due to the fact that ValueProxy's don't have an identity and on the backend it traverse through all properties of my entity. However by having a reference from Term2Term back to Term I can end up with a cyclic dependency.

i.e. Term A -> Term2Term.parent -> Term B -> Term2Term.child -> Term A

If I break one of the relationships (parent or child) from Term to Term2Term it serializes fine. However when I adda nother ValueProxy (Term A -> SomeValueProxy -> Term A ) that contains a property which maps back to the Term, I again get a stackoverflow however this time on the client.

I guess switching to EntityProxy would solve the problem as the properties don't automatically get serialized and for identity the stableId is used.

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment