X Tutup
Skip to content

Commit bcfef8a

Browse files
committed
support for JPA 2.0 TypedQuery interface and query vendor interfaces (SPR-6733)
1 parent 975dcd7 commit bcfef8a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

org.springframework.orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.commons.logging.Log;
2929
import org.apache.commons.logging.LogFactory;
3030

31+
import org.springframework.util.ClassUtils;
3132
import org.springframework.util.CollectionUtils;
3233

3334
/**
@@ -130,9 +131,17 @@ private static class SharedEntityManagerInvocationHandler implements InvocationH
130131

131132
private final Map properties;
132133

134+
private final ClassLoader proxyClassLoader;
135+
133136
public SharedEntityManagerInvocationHandler(EntityManagerFactory target, Map properties) {
134137
this.targetFactory = target;
135138
this.properties = properties;
139+
if (this.targetFactory instanceof EntityManagerFactoryInfo) {
140+
this.proxyClassLoader = ((EntityManagerFactoryInfo) this.targetFactory).getBeanClassLoader();
141+
}
142+
else {
143+
this.proxyClassLoader = EntityManagerFactory.class.getClassLoader();
144+
}
136145
}
137146

138147
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
@@ -225,7 +234,8 @@ else if (method.getName().equals("unwrap")) {
225234
if (result instanceof Query) {
226235
Query query = (Query) result;
227236
if (isNewEm) {
228-
result = Proxy.newProxyInstance(Query.class.getClassLoader(), new Class[] {Query.class},
237+
Class[] ifcs = ClassUtils.getAllInterfacesForClass(query.getClass(), this.proxyClassLoader);
238+
result = Proxy.newProxyInstance(this.proxyClassLoader, ifcs,
229239
new DeferredQueryInvocationHandler(query, target));
230240
isNewEm = false;
231241
}
@@ -257,7 +267,7 @@ private static class DeferredQueryInvocationHandler implements InvocationHandler
257267

258268
private final EntityManager em;
259269

260-
private DeferredQueryInvocationHandler(Query target, EntityManager em) {
270+
public DeferredQueryInvocationHandler(Query target, EntityManager em) {
261271
this.target = target;
262272
this.em = em;
263273
}

0 commit comments

Comments
 (0)
X Tutup