Browse Source

Initial support for JPA 3.2

Includes proxy support for Query#getSingleResultOrNull() and EntityManagerFactory#getName() invocations.

Closes gh-31157
pull/32347/head
Juergen Hoeller 2 years ago
parent
commit
5acee7b22e
  1. 7
      spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java
  2. 3
      spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java

7
spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -709,6 +709,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
} }
@Override @Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
switch (method.getName()) { switch (method.getName()) {
case "equals" -> { case "equals" -> {
@ -729,6 +730,10 @@ public abstract class AbstractEntityManagerFactoryBean implements
return proxy; return proxy;
} }
} }
case "getName" -> {
// Handle JPA 3.2 getName method locally.
return this.entityManagerFactoryBean.getPersistenceUnitName();
}
} }
try { try {

3
spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -85,6 +85,7 @@ public abstract class SharedEntityManagerCreator {
"execute", // jakarta.persistence.StoredProcedureQuery.execute() "execute", // jakarta.persistence.StoredProcedureQuery.execute()
"executeUpdate", // jakarta.persistence.Query.executeUpdate() "executeUpdate", // jakarta.persistence.Query.executeUpdate()
"getSingleResult", // jakarta.persistence.Query.getSingleResult() "getSingleResult", // jakarta.persistence.Query.getSingleResult()
"getSingleResultOrNull", // jakarta.persistence.Query.getSingleResultOrNull()
"getResultStream", // jakarta.persistence.Query.getResultStream() "getResultStream", // jakarta.persistence.Query.getResultStream()
"getResultList", // jakarta.persistence.Query.getResultList() "getResultList", // jakarta.persistence.Query.getResultList()
"list", // org.hibernate.query.Query.list() "list", // org.hibernate.query.Query.list()

Loading…
Cancel
Save