public Query createJpaQuery(String queryString) { Class<?> objectType = getQueryMethod().getReturnedObjectType(); //get original proxy query. Query oriProxyQuery; //must be hibernate QueryImpl QueryImpl query; if (useJpaSpec && getQueryMethod().isQueryForEntity()) { oriProxyQuery = getEntityManager().createNativeQuery(queryString, objectType); // QueryImpl query = AopTargetUtils.getTarget(oriProxyQuery); } else { oriProxyQuery = getEntityManager().createNativeQuery(queryString); query = AopTargetUtils.getTarget(oriProxyQuery); //find generic type ClassTypeInformation<?> ctif = ClassTypeInformation.from(objectType); TypeInformation<?> actualType = ctif.getActualType(); if (actualType == null){ actualType = ctif.getRawTypeInformation(); } Class<?> genericType = actualType.getType(); if (genericType != null && genericType != Void.class) { QueryBuilder.transform(query.getHibernateQuery(), genericType); } } //return the original proxy query, for a series of JPA actions, e.g.:close em. return oriProxyQuery; }
public Query bind(Query query, Object[] values) { //get proxy target if exist. //must be hibernate QueryImpl QueryImpl targetQuery = AopTargetUtils.getTarget(query); SQLQuery sqlQuery = (SQLQuery) targetQuery.getHibernateQuery(); Map<String, Object> params = getParams(values); if (!CollectionUtils.isEmpty(params)) { QueryBuilder.setParams(sqlQuery, params); } return query; }