-2

I'm creating Session factory object like following:

SessionFactory factory = new Configuration().configure().buildSessionFactory();

Which class mentions the database which I've mentioned in *.hbm.xml file ?

Rajat Shah
  • 11
  • 4

1 Answers1

0

The database to be used is defined in the hibernate.cfg.xml file. In this file, you can define the database connection stats as well as mapping the classes to be used if you so chose. An example of the connection stats here:

hibernate.cfg.xml form this tutorial:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
  <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:MKYONG</property>
  <property name="hibernate.connection.username">mkyong</property>
  <property name="hibernate.connection.password">password</property>
  <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
  <property name="hibernate.default_schema">MKYONG</property>
</session-factory>
</hibernate-configuration>

Also of note: Configuration - Hibernate Documentation

(Side note: Stuff at mkyong may sometimes be outdated but that dude damn near single handedly is responsible for me keeping my job at the moment. )

Old Schooled
  • 922
  • 7
  • 17