How can I set Datasource when I’m creating Hibernate SessionFactory?
If you happen to have your DataSource stored in JNDI, then simply use: configuration.setProperty( “hibernate.connection.datasource”, “java:comp/env/jdbc/yourDataSource”); 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: //retrieve … Read more