|
1 | 1 | /* |
2 | | - * Copyright 2002-2014 the original author or authors. |
| 2 | + * Copyright 2002-2017 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
33 | 33 | * <p>Primarily available for resolving a SessionFactory by JPA persistence unit name |
34 | 34 | * via the {@link #setPersistenceUnitName "persistenceUnitName"} bean property. |
35 | 35 | * |
| 36 | + * <p>Note that, for straightforward cases, you could also simply declare a factory method: |
| 37 | + * |
| 38 | + * <pre class="code"> |
| 39 | + * <bean id="sessionFactory" factory-bean="entityManagerFactory" factory-method="getSessionFactory"/> |
| 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 | + * @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 | + * |
36 | 57 | * @author Juergen Hoeller |
37 | 58 | * @since 3.1 |
38 | 59 | * @see #setPersistenceUnitName |
39 | 60 | * @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 |
40 | 63 | */ |
| 64 | +@Deprecated |
41 | 65 | public class HibernateJpaSessionFactoryBean extends EntityManagerFactoryAccessor implements FactoryBean<SessionFactory> { |
42 | 66 |
|
43 | 67 | @Override |
|
0 commit comments