From 1da766bc55371aca8ce969286f148aef9ce874ea Mon Sep 17 00:00:00 2001 From: Fay Wang Date: Fri, 17 Apr 2009 04:26:10 +0000 Subject: [PATCH] OPENJPA-1038: detect circular dependencies among embeddables and issue proper error message to avoid stack overflow git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@765846 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/openjpa/meta/ClassMetaData.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java index 5981ae1d5..6138fb998 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java @@ -1673,8 +1673,7 @@ public class ClassMetaData // are we the target of an embedded value? if (embed) { - if (_owner.getFieldMetaData().getDefiningMetaData(). - getDescribedType().isAssignableFrom(_type)) + if (recursiveEmbed(_owner)) throw new MetaDataException(_loc.get("recurse-embed", _owner)); // copy info from the "real" metadata for this type @@ -1765,6 +1764,17 @@ public class ClassMetaData } } + private boolean recursiveEmbed(ValueMetaData owner) { + ClassMetaData cm = owner.getFieldMetaData().getDefiningMetaData(); + if (cm.getDescribedType().isAssignableFrom(_type)) + return true; + ValueMetaData owner1 = cm.getEmbeddingMetaData(); + if (owner1 == null) + return false; + else + return recursiveEmbed(owner1); + } + /** * Validate resolved metadata. */