@@ -87,11 +87,14 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
87
87
88
88
private static final Method createQueryMethod ;
89
89
90
+ private static final Method getNamedQueryMethod ;
91
+
90
92
static {
91
93
// Hibernate 5.2's createQuery method declares a new subtype as return type,
92
94
// so we need to use reflection for binary compatibility with 5.0/5.1 here.
93
95
try {
94
96
createQueryMethod = Session .class .getMethod ("createQuery" , String .class );
97
+ getNamedQueryMethod = Session .class .getMethod ("getNamedQuery" , String .class );
95
98
}
96
99
catch (NoSuchMethodException ex ) {
97
100
throw new IllegalStateException ("Incompatible Hibernate Session API" , ex );
@@ -955,7 +958,8 @@ public List<?> findByNamedQuery(final String queryName, final Object... values)
955
958
@ Override
956
959
@ SuppressWarnings ({"rawtypes" , "deprecation" })
957
960
public List <?> doInHibernate (Session session ) throws HibernateException {
958
- org .hibernate .Query queryObject = session .getNamedQuery (queryName );
961
+ org .hibernate .Query queryObject = (org .hibernate .Query )
962
+ ReflectionUtils .invokeMethod (getNamedQueryMethod , session , queryName );
959
963
prepareQuery (queryObject );
960
964
if (values != null ) {
961
965
for (int i = 0 ; i < values .length ; i ++) {
@@ -986,7 +990,8 @@ public List<?> findByNamedQueryAndNamedParam(
986
990
@ Override
987
991
@ SuppressWarnings ({"rawtypes" , "deprecation" })
988
992
public List <?> doInHibernate (Session session ) throws HibernateException {
989
- org .hibernate .Query queryObject = session .getNamedQuery (queryName );
993
+ org .hibernate .Query queryObject = (org .hibernate .Query )
994
+ ReflectionUtils .invokeMethod (getNamedQueryMethod , session , queryName );
990
995
prepareQuery (queryObject );
991
996
if (values != null ) {
992
997
for (int i = 0 ; i < values .length ; i ++) {
@@ -1006,7 +1011,8 @@ public List<?> findByNamedQueryAndValueBean(final String queryName, final Object
1006
1011
@ Override
1007
1012
@ SuppressWarnings ({"rawtypes" , "deprecation" })
1008
1013
public List <?> doInHibernate (Session session ) throws HibernateException {
1009
- org .hibernate .Query queryObject = session .getNamedQuery (queryName );
1014
+ org .hibernate .Query queryObject = (org .hibernate .Query )
1015
+ ReflectionUtils .invokeMethod (getNamedQueryMethod , session , queryName );
1010
1016
prepareQuery (queryObject );
1011
1017
queryObject .setProperties (valueBean );
1012
1018
return queryObject .list ();
@@ -1256,7 +1262,7 @@ public CloseSuppressingInvocationHandler(Session target) {
1256
1262
}
1257
1263
1258
1264
@ Override
1259
- @ SuppressWarnings (" deprecation" )
1265
+ @ SuppressWarnings ({ "rawtypes" , " deprecation"} )
1260
1266
public Object invoke (Object proxy , Method method , Object [] args ) throws Throwable {
1261
1267
// Invocation on Session interface coming in...
1262
1268
0 commit comments