I am new bee to Hibernate and trying out things. One thing that seems to amuse all is how to connect to different databases? I have two questions here:
It cannot be done using one hibernate configuration file. You need to have two configurations files for it.
To configure mysql database
hibernate-mysql.cfg.xml
To configure oracle database
hibernate-oracle.cfg.xml
In Details, mysql configuration file be like this.
false
com.mysql.jdbc.Driver
PASSWORD
jdbc:mysql://localhost:3306/UR_DB_NAME
USERNAME
org.hibernate.dialect.MySQLDialect
true
In Details, oracle configuration file be like this.
false
oracle.jdbc.driver.OracleDriver
PASSWORD
jdbc:oracle:thin:UR DB NAME
USERNAME
org.hibernate.dialect.Oracle10gDialect
true
And code should be like this.
mysql configuration
private static SessionFactory sessionAnnotationFactory;
sessionAnnotationFactory = new Configuration().configure("hibernate-mysql.cfg.xml").buildSessionFactory();
Session session = sessionAnnotationFactory.openSession();
oracle sql configuration
sessionAnnotationFactory = new Configuration().configure("hibernate-oracle.cfg.xml").buildSessionFactory();
Session session = sessionAnnotationFactory.openSession()