Skip to content

Commit bb41cce

Browse files
committed
Deprecate HibernateJpaSessionFactoryBean (against Hibernate 5.2)
Issue: SPR-16016 (cherry picked from commit 66a6fda)
1 parent d0d4421 commit bb41cce

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaSessionFactoryBean.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,11 +33,35 @@
3333
* <p>Primarily available for resolving a SessionFactory by JPA persistence unit name
3434
* via the {@link #setPersistenceUnitName "persistenceUnitName"} bean property.
3535
*
36+
* <p>Note that, for straightforward cases, you could also simply declare a factory method:
37+
*
38+
* <pre class="code">
39+
* &lt;bean id="sessionFactory" factory-bean="entityManagerFactory" factory-method="getSessionFactory"/&gt;
40+
* </pre>
41+
*
42+
* <p>And as of JPA 2.1, {@link EntityManagerFactory#unwrap} provides a nice approach as well,
43+
* in particular within configuration class arrangements:
44+
*
45+
* <pre class="code">
46+
* &#064;Bean
47+
* public SessionFactory sessionFactory(@Qualifier("entityManagerFactory") EntityManagerFactory emf) {
48+
* return emf.unwrap(SessionFactory.class);
49+
* }
50+
* </pre>
51+
*
52+
* Please note: Since Hibernate 5.2 changed its {@code SessionFactory} interface to extend JPA's
53+
* {@code EntityManagerFactory}, you may get conflicts when injecting by type, with both the
54+
* original factory and your custom {@code SessionFactory} matching {@code EntityManagerFactory}.
55+
* An explicit qualifier for the original factory (as indicated above) is recommended here.
56+
*
3657
* @author Juergen Hoeller
3758
* @since 3.1
3859
* @see #setPersistenceUnitName
3960
* @see #setEntityManagerFactory
61+
* @deprecated as of Spring Framework 4.3.12 against Hibernate 5.2, in favor of a custom solution
62+
* based on {@link EntityManagerFactory#unwrap} with explicit qualifiers and/or primary markers
4063
*/
64+
@Deprecated
4165
public class HibernateJpaSessionFactoryBean extends EntityManagerFactoryAccessor implements FactoryBean<SessionFactory> {
4266

4367
@Override

0 commit comments

Comments
 (0)