Early removal of 5.x-deprecated code

Closes gh-27686
This commit is contained in:
Juergen Hoeller
2021-11-18 09:18:06 +01:00
parent 17cdd97c37
commit 4750a9430c
132 changed files with 89 additions and 9216 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@@ -112,27 +112,14 @@ public class OpenSessionInterceptor implements MethodInterceptor, InitializingBe
* @see FlushMode#MANUAL
*/
protected Session openSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
Session session = openSession();
if (session == null) {
try {
session = sessionFactory.openSession();
session.setHibernateFlushMode(FlushMode.MANUAL);
}
catch (HibernateException ex) {
throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex);
}
try {
Session session = sessionFactory.openSession();
session.setHibernateFlushMode(FlushMode.MANUAL);
return session;
}
catch (HibernateException ex) {
throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex);
}
return session;
}
/**
* Open a Session for the given SessionFactory.
* @deprecated as of 5.0, in favor of {@link #openSession(SessionFactory)}
*/
@Deprecated
@Nullable
protected Session openSession() throws DataAccessResourceFailureException {
return null;
}
}

View File

@@ -353,14 +353,6 @@ public class PersistenceAnnotationBeanPostProcessor
return pvs;
}
@Deprecated
@Override
public PropertyValues postProcessPropertyValues(
PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) {
return postProcessProperties(pvs, bean, beanName);
}
@Override
public void postProcessBeforeDestruction(Object bean, String beanName) {
EntityManager emToClose = this.extendedEntityManagersToClose.remove(bean);

View File

@@ -1,92 +0,0 @@
/*
* Copyright 2002-2017 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.orm.jpa.vendor;
import java.lang.reflect.Method;
import jakarta.persistence.EntityManagerFactory;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.EntityManagerFactoryAccessor;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
/**
* Simple {@code FactoryBean} that exposes the underlying {@link SessionFactory}
* behind a Hibernate-backed JPA {@link EntityManagerFactory}.
*
* <p>Primarily available for resolving a SessionFactory by JPA persistence unit name
* via the {@link #setPersistenceUnitName "persistenceUnitName"} bean property.
*
* <p>Note that, for straightforward cases, you could also simply declare a factory method:
*
* <pre class="code">
* &lt;bean id="sessionFactory" factory-bean="entityManagerFactory" factory-method="getSessionFactory"/&gt;
* </pre>
*
* <p>And as of JPA 2.1, {@link EntityManagerFactory#unwrap} provides a nice approach as well,
* in particular within configuration class arrangements:
*
* <pre class="code">
* &#064;Bean
* public SessionFactory sessionFactory(@Qualifier("entityManagerFactory") EntityManagerFactory emf) {
* return emf.unwrap(SessionFactory.class);
* }
* </pre>
*
* Please note: Since Hibernate 5.2 changed its {@code SessionFactory} interface to extend JPA's
* {@code EntityManagerFactory}, you may get conflicts when injecting by type, with both the
* original factory and your custom {@code SessionFactory} matching {@code EntityManagerFactory}.
* An explicit qualifier for the original factory (as indicated above) is recommended here.
*
* @author Juergen Hoeller
* @since 3.1
* @see #setPersistenceUnitName
* @see #setEntityManagerFactory
* @deprecated as of Spring Framework 4.3.12 against Hibernate 5.2, in favor of a custom solution
* based on {@link EntityManagerFactory#unwrap} with explicit qualifiers and/or primary markers
*/
@Deprecated
public class HibernateJpaSessionFactoryBean extends EntityManagerFactoryAccessor implements FactoryBean<SessionFactory> {
@Override
@Nullable
public SessionFactory getObject() {
EntityManagerFactory emf = getEntityManagerFactory();
Assert.state(emf != null, "EntityManagerFactory must not be null");
try {
Method getSessionFactory = emf.getClass().getMethod("getSessionFactory");
return (SessionFactory) ReflectionUtils.invokeMethod(getSessionFactory, emf);
}
catch (NoSuchMethodException ex) {
throw new IllegalStateException("No compatible Hibernate EntityManagerFactory found: " + ex);
}
}
@Override
public Class<?> getObjectType() {
return SessionFactory.class;
}
@Override
public boolean isSingleton() {
return true;
}
}