NOTE: I know I can fix this using scripts or a database field, but I am curious about accessing the connection string.
I have two testing environments. Each has its own database, one for Chinese and one for English data. Otherwise the two databases are identical.
The only difference is the connection string in my beans.xml (ctest vs ctestzh).
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver" />
<property name="jdbcUrl" value="jdbc:postgresql://localhost/ctest?useUnicode=true&characterEncoding=utf8" />
<property name="user" value="testuser" />
<property name="password" value="xxxx" />
....
</bean>
<!-- Hibernate
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver" />
<property name="jdbcUrl" value="jdbc:postgresql://localhost/ctestzh?useUnicode=true&characterEncoding=utf8" />
<property name="user" value="testuser" />
<property name="password" value="xxxx" />
.....
</bean>-->
I use an xml configuration file that configures my application to either process English or Chinese data. If I forget to change the beans.xml to the appropriate data, however, I corrupt the database (i.e., put Chinese data in the English database)
Can I access the connection string in code so I can fail if I am connected to the wrong database? I have looked at SessionFactory, but saw nothing obvious.