0

Hibernate 5.4

The dialect is known, I need to implement the following method :

@Bean
public org.hibernate.SessionFactory sessionFactory(DataSource dataSource) {
    // hibernate.dialect = "org.hibernate.dialect.PostgreSQL95Dialect"
    // ???
}
Ilya
  • 720
  • 6
  • 14

1 Answers1

0

Maybe creating one via a Configuration would work for you, as descibed here:

Create Sessionfactory in Hibernate

Configuration cfg = new Configuration()...

.setProperty("hibernate.connection.username", "myuser"); .setProperty("hibernate.connection.password", "mypassword") .setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/hibernate_example")

SessionFactory sessionFactory = cfg.buildSessionFactory();

Or you choose to use the Spring LocalSessionFactory-Class like so:

lsfb = new LocalSessionFactoryBean()  [from hib5-package]
lsfb.setDataSource( yourDS );
return lsfb.getObject();

Setting the Datasource this might help: Luiggi Mendoza on SO (How can I set Datasource when I'm creating Hibernate SessionFactory? )

But if you use a custom data source provider like Apache DBCP or BoneCP and you don't want to use a dependency injection framework like Spring, then you may inject it on the StandardServiceRegistryBuilder before creating the SessionFactory...

SvenJu
  • 31
  • 1
  • 5