I'm using spring 3.2 and hibernate 4.2. i have 2 beans: datasource (c3p0) and sessionFactory (LocalSessionFactoryBean) with property file (application.properties).
when i define the datasource using java configuration with explicit username and password all works good. during startup c3p0 logs its configuration. e.g. 'properties' property is:
properties -> {user=******, password=******}
that's the exact output
but when i define the same datasource in xml (also with user and password) instead of in java, the application behaves differently.
'properties' property shows
properties -> {java.runtime.name=xxx, line.separator=xxx, maven.home=xxx, ...}
and all environment variables but nothing about user or password. and it refuses to connect to database:
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
but when in application.properties i add:
hibernate.connection.username=xxx
hibernate.connection.password=xxx
c3p0 again prints all the environment properties without user and password but connection succeeds. well, ok: pooling can be pushed to session factory but credentials must be in the datasource
so what's going on? i want to have datasource with credentials and pooling configuration and hibernate session factory with hibernate configuration.
in case it matters. below is my configuration:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="xxx.model" />
<property name="hibernateProperties">
<util:properties location="classpath:/spring/application.properties" />
</property>
</bean>
xml ds:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
<property name="user" value="xxx"/>
<property name="password" value="xxx"/>
<property name="jdbcUrl" value="xxx"/>
</bean>
and java ds:
@Bean
public DataSource dataSource() throws PropertyVetoException {
ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setDriverClass("oracle.jdbc.driver.OracleDriver");
ds.setUser("xxx");
ds.setPassword("xxx");
ds.setJdbcUrl("xxx");
return ds;
}