@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2014 the original author or authors .
* Copyright 2002 - 2016 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -33,6 +33,7 @@ import java.util.Set;
@@ -33,6 +33,7 @@ import java.util.Set;
import javax.persistence.EntityManager ;
import javax.persistence.EntityManagerFactory ;
import javax.persistence.PersistenceException ;
import javax.persistence.Query ;
import javax.persistence.spi.PersistenceProvider ;
import javax.persistence.spi.PersistenceUnitInfo ;
import javax.sql.DataSource ;
@ -384,6 +385,24 @@ public abstract class AbstractEntityManagerFactoryBean implements
@@ -384,6 +385,24 @@ public abstract class AbstractEntityManagerFactoryBean implements
return ExtendedEntityManagerCreator . createApplicationManagedEntityManager ( rawEntityManager , this , true ) ;
}
// Look for Query arguments, primarily JPA 2.1's addNamedQuery(String, Query)
if ( args ! = null ) {
for ( int i = 0 ; i < args . length ; i + + ) {
Object arg = args [ i ] ;
if ( arg instanceof Query & & Proxy . isProxyClass ( arg . getClass ( ) ) ) {
// Assumably a Spring-generated proxy from SharedEntityManagerCreator:
// since we're passing it back to the native EntityManagerFactory,
// let's unwrap it to the original Query object from the provider.
try {
args [ i ] = ( ( Query ) arg ) . unwrap ( null ) ;
}
catch ( RuntimeException ex ) {
// Ignore - simply proceed with given Query object then
}
}
}
}
// Standard delegation to the native factory, just post-processing EntityManager return values
Object retVal = method . invoke ( this . nativeEntityManagerFactory , args ) ;
if ( retVal instanceof EntityManager ) {