I am using hibernate 3.x with Jboss. Currently we support multiple databases.
Now in runtime, how can I know the underlying database information ? at least name or database-dialect? (e.g. MySQL, Derby, Oracle, etc)?
Can any one suggests any way to find this information? I thought hibernate SessionFactory class will provide such api - but it is not?
Thanks in advance,
You will have to make sure that you have testdb database available in your MySQL database and you have a user test available to access the database. The XML configuration file must conform to the Hibernate 3 Configuration DTD, which is available at http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd.
Hibernate also requires a set of configuration settings related to database and other related parameters. All such information is usually supplied as a standard Java properties file called hibernate. properties, or as an XML file named hibernate. cfg.
dialect This property makes Hibernate generate the appropriate SQL for the chosen database.
Easiest way is to get the currently configured properties and then get your db URL using key "hibernate.connection.url". The following code prints current session url
System.out.println(sessionFactory.getProperties().get("hibernate.connection.url"))
on my system I get
jdbc:postgresql://localhost:15432/tempdb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With