Browse files

DATAJPA-241 - Polished logging in NamedQuery.

  • Loading branch information...
1 parent 54675ff commit c90d1c122dbc4fe6cc49f8fd35399444b3b6a9fa @olivergierke olivergierke committed Aug 2, 2012
Showing with 12 additions and 10 deletions.
  1. +12 −10 src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java
View
22 src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java
@@ -56,14 +56,12 @@ private NamedQuery(JpaQueryMethod method, EntityManager em) {
Parameters parameters = method.getParameters();
+ // Let's see if the referenced named query exists
+ em.createNamedQuery(queryName);
+
if (parameters.hasSortParameter()) {
throw new IllegalStateException(String.format("Finder method %s is backed " + "by a NamedQuery and must "
- + "not contain a sort parameter as we " + "cannot modify the query! Use @Query instead!", method));
- }
-
- if (parameters.hasPageableParameter()) {
- LOG.warn("Finder method {} is backed by a NamedQuery" + " but contains a Pageable parameter! Sorting delivered "
- + "via this Pageable will not be applied!", method);
+ + "not contain a sort parameter as we cannot modify the query! Use @Query instead!", method));
}
boolean weNeedToCreateCountQuery = !hasNamedQuery(em, countQueryName)
@@ -74,8 +72,10 @@ private NamedQuery(JpaQueryMethod method, EntityManager em) {
throw QueryCreationException.create(method, CANNOT_EXTRACT_QUERY);
}
- // Let's see if the referenced named query exists
- em.createNamedQuery(queryName);
+ if (parameters.hasPageableParameter()) {
+ LOG.warn("Finder method {} is backed by a NamedQuery" + " but contains a Pageable parameter! Sorting delivered "
+ + "via this Pageable will not be applied!", method);
+ }
}
/**
@@ -108,7 +108,9 @@ public static RepositoryQuery lookupFrom(JpaQueryMethod method, EntityManager em
LOG.debug("Looking up named query {}", queryName);
try {
- return new NamedQuery(method, em);
+ RepositoryQuery query = new NamedQuery(method, em);
+ LOG.debug("Found named query {}!", queryName);
+ return query;
} catch (IllegalArgumentException e) {
return null;
}
@@ -145,4 +147,4 @@ protected Query doCreateQuery(Object[] values) {
return createBinder(values).bind(countQuery);
}
-}
+}

0 comments on commit c90d1c1

Please sign in to comment.