Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know underlying database name from hibernate provider

Tags:

java

hibernate

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,

like image 656
user530081 Avatar asked Dec 04 '10 01:12

user530081


People also ask

How do I access Hibernate database?

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.

What is the name of the file which stores the configuration for Hibernate?

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.

Which Hibernate property do you use to configure your chosen database?

dialect This property makes Hibernate generate the appropriate SQL for the chosen database.


1 Answers

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
like image 89
renuka28 Avatar answered Sep 28 '22 09:09

renuka28