EntityManagerFactory.unwrap(java.lang.Class<T>) with explicit qualifiers and/or primary markers@Deprecated public class HibernateJpaSessionFactoryBean extends EntityManagerFactoryAccessor implements org.springframework.beans.factory.FactoryBean<SessionFactory>
FactoryBean that exposes the underlying SessionFactory
behind a Hibernate-backed JPA EntityManagerFactory.
Primarily available for resolving a SessionFactory by JPA persistence unit name
via the "persistenceUnitName" bean property.
Note that, for straightforward cases, you could also simply declare a factory method:
<bean id="sessionFactory" factory-bean="entityManagerFactory" factory-method="getSessionFactory"/>
And as of JPA 2.1, EntityManagerFactory.unwrap(java.lang.Class<T>) provides a nice approach as well,
in particular within configuration class arrangements:
@Bean
public SessionFactory sessionFactory(@Qualifier("entityManagerFactory") EntityManagerFactory emf) {
return emf.unwrap(SessionFactory.class);
}
Please note: Since Hibernate 5.2 changed its SessionFactory interface to extend JPA's
EntityManagerFactory, you may get conflicts when injecting by type, with both the
original factory and your custom SessionFactory matching EntityManagerFactory.
An explicit qualifier for the original factory (as indicated above) is recommended here.EntityManagerFactoryAccessor.setPersistenceUnitName(java.lang.String),
EntityManagerFactoryAccessor.setEntityManagerFactory(javax.persistence.EntityManagerFactory)logger| Constructor and Description |
|---|
HibernateJpaSessionFactoryBean()
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
SessionFactory |
getObject()
Deprecated.
|
Class<?> |
getObjectType()
Deprecated.
|
boolean |
isSingleton()
Deprecated.
|
createEntityManager, getEntityManagerFactory, getJpaPropertyMap, getPersistenceUnitName, getTransactionalEntityManager, obtainEntityManagerFactory, setBeanFactory, setEntityManagerFactory, setJpaProperties, setJpaPropertyMap, setPersistenceUnitNamepublic HibernateJpaSessionFactoryBean()
@Nullable public SessionFactory getObject()
getObject in interface org.springframework.beans.factory.FactoryBean<SessionFactory>public Class<?> getObjectType()
getObjectType in interface org.springframework.beans.factory.FactoryBean<SessionFactory>public boolean isSingleton()
isSingleton in interface org.springframework.beans.factory.FactoryBean<SessionFactory>