diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FetchGroup.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FetchGroup.java index 69c91bb3e..cd7c86da6 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FetchGroup.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FetchGroup.java @@ -20,6 +20,7 @@ package org.apache.openjpa.meta; import java.io.Serializable; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -108,6 +109,9 @@ public class FetchGroup if (fg._includes != null) for (Iterator itr = fg._includes.iterator(); itr.hasNext();) addDeclaredInclude((String) itr.next()); + if (fg._containedBy != null) + this._containedBy = new HashSet(fg._containedBy); + if (fg._depths != null) { Map.Entry entry; for (Iterator itr = fg._depths.entrySet().iterator(); @@ -155,7 +159,7 @@ public class FetchGroup if (_includes != null) { if (_includes.contains(fgName)) return true; - if (recurse) { + if (recurse && _meta!=null) { FetchGroup fg; for (Iterator i = _includes.iterator(); i.hasNext();) { fg = _meta.getFetchGroup((String) i.next()); @@ -177,14 +181,18 @@ public class FetchGroup } /** - * Sets this receiver as one of the included fetch groups of the given + * Adds this receiver as one of the included fetch groups of the given * parent. - * The parent fecth grop must include this receiver before this call. + * The parent fecth group will include this receiver as a side-effect of + * this call. * * @see #includes(String, boolean) * @see #addDeclaredInclude(String) + * + * @return true if given parent is a new addition. false othrwise. + * @since 1.1.1 */ - public boolean setContainedBy(FetchGroup parent) { + public boolean addContainedBy(FetchGroup parent) { parent.addDeclaredInclude(this.getName()); if (_containedBy==null) _containedBy = new HashSet(); @@ -195,11 +203,12 @@ public class FetchGroup * Gets the name of the fetch groups in which this receiver has been * included. * - * @see #setContainedBy(FetchGroup) + * @see #addContainedBy(FetchGroup) + * @since 1.1.1 */ - public String[] getContainedBy() { - return (_containedBy == null) ? new String[0] - : (String[]) _containedBy.toArray(new String[_containedBy.size()]); + public Set getContainedBy() { + return (_containedBy == null) ? Collections.EMPTY_SET : + Collections.unmodifiableSet(_containedBy); } /** diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java index c8998a7ee..16d8e9597 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java @@ -902,7 +902,7 @@ public class AnnotationPersistenceMetaDataParser fg = meta.getFetchGroup(group.name()); String[] includedFetchGropNames = fg.getDeclaredIncludes(); for (String includedFectchGroupName:includedFetchGropNames) - meta.getFetchGroup(includedFectchGroupName).setContainedBy(fg); + meta.getFetchGroup(includedFectchGroupName).addContainedBy(fg); } for (FetchGroup group : groups) { @@ -925,9 +925,9 @@ public class AnnotationPersistenceMetaDataParser meta, attr.name())); field.setInFetchGroup(fg.getName(), true); - String[] parentFetchGroups = fg.getContainedBy(); - for (String parentFetchGroup:parentFetchGroups) - field.setInFetchGroup(parentFetchGroup, true); + Set parentFetchGroups = fg.getContainedBy(); + for (Object parentFetchGroup:parentFetchGroups) + field.setInFetchGroup(parentFetchGroup.toString(), true); if (attr.recursionDepth() != Integer.MIN_VALUE) fg.setRecursionDepth(field, attr.recursionDepth()); }