提交 d631b4cc 编写于 作者: J Juergen Hoeller

HibernateTemplate reflectively calls getNamedQuery (for runtime compatibility...

HibernateTemplate reflectively calls getNamedQuery (for runtime compatibility with Hibernate 5.0/5.1 vs 5.2)

Issue: SPR-14676
上级 8c566068
...@@ -87,11 +87,14 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean ...@@ -87,11 +87,14 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
private static final Method createQueryMethod; private static final Method createQueryMethod;
private static final Method getNamedQueryMethod;
static { static {
// Hibernate 5.2's createQuery method declares a new subtype as return type, // Hibernate 5.2's createQuery method declares a new subtype as return type,
// so we need to use reflection for binary compatibility with 5.0/5.1 here. // so we need to use reflection for binary compatibility with 5.0/5.1 here.
try { try {
createQueryMethod = Session.class.getMethod("createQuery", String.class); createQueryMethod = Session.class.getMethod("createQuery", String.class);
getNamedQueryMethod = Session.class.getMethod("getNamedQuery", String.class);
} }
catch (NoSuchMethodException ex) { catch (NoSuchMethodException ex) {
throw new IllegalStateException("Incompatible Hibernate Session API", ex); throw new IllegalStateException("Incompatible Hibernate Session API", ex);
...@@ -955,7 +958,8 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean ...@@ -955,7 +958,8 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
@Override @Override
@SuppressWarnings({"rawtypes", "deprecation"}) @SuppressWarnings({"rawtypes", "deprecation"})
public List<?> doInHibernate(Session session) throws HibernateException { public List<?> doInHibernate(Session session) throws HibernateException {
org.hibernate.Query queryObject = session.getNamedQuery(queryName); org.hibernate.Query queryObject = (org.hibernate.Query)
ReflectionUtils.invokeMethod(getNamedQueryMethod, session, queryName);
prepareQuery(queryObject); prepareQuery(queryObject);
if (values != null) { if (values != null) {
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
...@@ -986,7 +990,8 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean ...@@ -986,7 +990,8 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
@Override @Override
@SuppressWarnings({"rawtypes", "deprecation"}) @SuppressWarnings({"rawtypes", "deprecation"})
public List<?> doInHibernate(Session session) throws HibernateException { public List<?> doInHibernate(Session session) throws HibernateException {
org.hibernate.Query queryObject = session.getNamedQuery(queryName); org.hibernate.Query queryObject = (org.hibernate.Query)
ReflectionUtils.invokeMethod(getNamedQueryMethod, session, queryName);
prepareQuery(queryObject); prepareQuery(queryObject);
if (values != null) { if (values != null) {
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
...@@ -1006,7 +1011,8 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean ...@@ -1006,7 +1011,8 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
@Override @Override
@SuppressWarnings({"rawtypes", "deprecation"}) @SuppressWarnings({"rawtypes", "deprecation"})
public List<?> doInHibernate(Session session) throws HibernateException { public List<?> doInHibernate(Session session) throws HibernateException {
org.hibernate.Query queryObject = session.getNamedQuery(queryName); org.hibernate.Query queryObject = (org.hibernate.Query)
ReflectionUtils.invokeMethod(getNamedQueryMethod, session, queryName);
prepareQuery(queryObject); prepareQuery(queryObject);
queryObject.setProperties(valueBean); queryObject.setProperties(valueBean);
return queryObject.list(); return queryObject.list();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册