From 7c07cc6d1da3313455114ffe00b120ab8d1a2ba6 Mon Sep 17 00:00:00 2001 From: Pinaki Poddar Date: Mon, 10 Sep 2007 16:20:08 +0000 Subject: [PATCH] OPENJPA-357, OPENJPA-358: Checking for user error of wrong fetch group inclusion git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@574293 13f79535-47bb-0310-9956-ffa450edef68 --- .../AnnotationPersistenceMetaDataParser.java | 16 +++++++++++++--- .../openjpa/persistence/localizer.properties | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) 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 16d8e9597..e4e8b9bbe 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 @@ -109,6 +109,8 @@ import org.apache.openjpa.util.ImplHelper; import org.apache.openjpa.util.InternalException; import org.apache.openjpa.util.MetaDataException; import org.apache.openjpa.util.UnsupportedException; +import org.apache.openjpa.util.UserException; + import serp.util.Numbers; import serp.util.Strings; @@ -897,12 +899,20 @@ public class AnnotationPersistenceMetaDataParser fg.addDeclaredInclude(s); } } - + // Add the parent-child style bi-links between fetch groups in a + // separate pass. for (FetchGroup group:groups) { fg = meta.getFetchGroup(group.name()); String[] includedFetchGropNames = fg.getDeclaredIncludes(); - for (String includedFectchGroupName:includedFetchGropNames) - meta.getFetchGroup(includedFectchGroupName).addContainedBy(fg); + for (String includedFectchGroupName:includedFetchGropNames) { + org.apache.openjpa.meta.FetchGroup child = + meta.getFetchGroup(includedFectchGroupName); + if (child == null) + throw new UserException(_loc.get("missing-included-fg", + meta.getDescribedType().getName(), fg.getName(), + includedFectchGroupName)); + child.addContainedBy(fg); + } } for (FetchGroup group : groups) { diff --git a/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties b/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties index c276ef84e..b19b4774b 100644 --- a/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties +++ b/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties @@ -59,6 +59,9 @@ unnamed-fg: "{0}" declares an unnamed fetch group. All fetch groups \ bad-fg-field: Fetch group "{0}" in type "{1}" includes field "{2}", but \ this field is not declared in "{1}", or is not persistent. Currently, \ OpenJPA only supports declared fields in fetch groups. +missing-included-fg:"{0}" declares a fecth group "{1}" includes "{2}". But \ + the included fetch group "{2}" can not be found in "{0}". Currently, all \ + included fetch groups must be declared within the same entity scope. not-update-delete-query: Cannot perform an update or delete operation \ on select query: "{0}". not-select-query: Cannot perform a select on update or delete query: "{0}". @@ -141,3 +144,4 @@ EntityManagerFactory-cat: Persistence.Advanced EntityManagerFactory-displayorder: 50 EntityManagerFactory-expert: true EntityManagerFactory-interface: org.apache.openjpa.persistence.EntityManagerFactoryImpl +