Skip to content

Commit 66a6fda

Browse files
committed
Deprecate HibernateJpaSessionFactoryBean (against Hibernate 5.2)
Issue: SPR-16016
1 parent 03b6828 commit 66a6fda

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.
@@ -34,11 +34,35 @@
3434
* <p>Primarily available for resolving a SessionFactory by JPA persistence unit name
3535
* via the {@link #setPersistenceUnitName "persistenceUnitName"} bean property.
3636
*
37+
* <p>Note that, for straightforward cases, you could also simply declare a factory method:
38+
*
39+
* <pre class="code">
40+
* &lt;bean id="sessionFactory" factory-bean="entityManagerFactory" factory-method="getSessionFactory"/&gt;
41+
* </pre>
42+
*
43+
* <p>And as of JPA 2.1, {@link EntityManagerFactory#unwrap} provides a nice approach as well,
44+
* in particular within configuration class arrangements:
45+
*
46+
* <pre class="code">
47+
* &#064;Bean
48+
* public SessionFactory sessionFactory(@Qualifier("entityManagerFactory") EntityManagerFactory emf) {
49+
* return emf.unwrap(SessionFactory.class);
50+
* }
51+
* </pre>
52+
*
53+
* Please note: Since Hibernate 5.2 changed its {@code SessionFactory} interface to extend JPA's
54+
* {@code EntityManagerFactory}, you may get conflicts when injecting by type, with both the
55+
* original factory and your custom {@code SessionFactory} matching {@code EntityManagerFactory}.
56+
* An explicit qualifier for the original factory (as indicated above) is recommended here.
57+
*
3758
* @author Juergen Hoeller
3859
* @since 3.1
3960
* @see #setPersistenceUnitName
4061
* @see #setEntityManagerFactory
62+
* @deprecated as of Spring Framework 4.3.12 against Hibernate 5.2, in favor of a custom solution
63+
* based on {@link EntityManagerFactory#unwrap} with explicit qualifiers and/or primary markers
4164
*/
65+
@Deprecated
4266
public class HibernateJpaSessionFactoryBean extends EntityManagerFactoryAccessor implements FactoryBean<SessionFactory> {
4367

4468
@Override

0 commit comments

Comments
 (0)