@Configuration
@PropertySource("classpath:persistence-mysql.properties")
public class HibernateConfig
extends java.lang.Object
Modifier and Type | Field | Description |
---|---|---|
private org.springframework.core.env.Environment |
env |
Constructor | Description |
---|---|
HibernateConfig() |
Modifier and Type | Method | Description |
---|---|---|
javax.sql.DataSource |
dataSource() |
Define
dataSource bean. |
(package private) java.util.Properties |
hibernateProperties() |
Define
Properties bean, which is needed to set up hibernate
SessionFactoryBean . |
org.springframework.orm.hibernate5.LocalSessionFactoryBean |
sessionFactory() |
Define
LocalSessionFactoryBean , it bootstraps the SessionFactory
from annotation scanning. |
org.springframework.orm.hibernate5.HibernateTransactionManager |
transactionManager(org.hibernate.SessionFactory sessionFactory) |
Configure the
HibernateTransactionManager , binds a Hibernate
Session from the specified factory to the thread. |
@Bean public javax.sql.DataSource dataSource()
dataSource
bean. The DataSource object is needed by
SessionFactoryBean.@Bean java.util.Properties hibernateProperties()
Properties
bean, which is needed to set up hibernate
SessionFactoryBean
.@Bean public org.springframework.orm.hibernate5.LocalSessionFactoryBean sessionFactory()
LocalSessionFactoryBean
, it bootstraps the SessionFactory
from annotation scanning. And it can also provide a SessionFactory
which is needed to get the Session
object.@Bean @Autowired public org.springframework.orm.hibernate5.HibernateTransactionManager transactionManager(org.hibernate.SessionFactory sessionFactory)
HibernateTransactionManager
, binds a Hibernate
Session from the specified factory to the thread. SessionFactory.getCurrentSession()
is required for Hibernate access code that needs to support this transaction
handling mechanism, with the SessionFactory being configured with SpringSessionContext.sessionFactory
- An autowired SessionFactory object