From fcd072a2c59869c4cd6a8eb8ee715675a6c33dbc Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Thu, 14 Sep 2006 18:21:19 +0000 Subject: [PATCH] Fixed bug where NamedNativeQuery/NamedNativeQueries was not being examined when looking up named queries, which could result in them not being found if the metadata has not yet been parsed completely git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@443432 13f79535-47bb-0310-9956-ffa450edef68 --- .../PersistenceMetaDataFactory.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java index c2f2c305c..39e686dbf 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java @@ -30,6 +30,8 @@ import javax.persistence.Entity; import javax.persistence.MappedSuperclass; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; +import javax.persistence.NamedNativeQueries; +import javax.persistence.NamedNativeQuery; import org.apache.openjpa.lib.conf.Configurable; import org.apache.openjpa.lib.conf.Configuration; @@ -277,6 +279,13 @@ public class PersistenceMetaDataFactory hasNamedQuery(queryName, ((NamedQueries) cls.getAnnotation (NamedQueries.class)).value())) return cls; + if (cls.isAnnotationPresent(NamedNativeQuery.class) && hasNamedNativeQuery + (queryName, (NamedNativeQuery) cls.getAnnotation(NamedNativeQuery.class))) + return cls; + if (cls.isAnnotationPresent(NamedNativeQueries.class) && + hasNamedNativeQuery(queryName, ((NamedNativeQueries) cls.getAnnotation + (NamedNativeQueries.class)).value())) + return cls; } return null; } @@ -289,6 +298,15 @@ public class PersistenceMetaDataFactory return false; } + private boolean hasNamedNativeQuery(String query, + NamedNativeQuery... queries) { + for (NamedNativeQuery q : queries) { + if (query.equals(q.name())) + return true; + } + return false; + } + @Override protected MetaDataFilter newMetaDataFilter() { return new ClassAnnotationMetaDataFilter(new Class[]{