Tuesday, May 13, 2014

hibernate.cfg.xml

what is this. why we need this.
Hibernate needs to know "in Advance" the mapping details that defines how the java classes are related to database tables.
Hibernate needs to set configuration settings related to database and other related parameters.

The information will be given through a standard java property file called "hibernate.properties"  or the "hibernate.cfg.xml".

The file will reside inside the root directory of your application classpath.


basically this file may look like this

---------------------

"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


  com.mysql.jdbc.Driver
  jdbc:mysql://localhost:3306/mkyong
  root
  root123
  org.hibernate.dialect.MySQLDialect
 
  true
 
 




let's see what these all about

S.N.Properties and Description
1hibernate.dialect 
This property makes Hibernate generate the appropriate SQL for the chosen database.
2hibernate.connection.driver_class 
The JDBC driver class.
3hibernate.connection.url 
The JDBC URL to the database instance.
4hibernate.connection.username 
The database username.
5hibernate.connection.password 
The database password.
6hibernate.connection.pool_size 
Limits the number of connections waiting in the Hibernate database connection pool.
7hibernate.connection.autocommit 
Allows autocommit mode to be used for the JDBC connection.

If you are using a database along with an application server and JNDI then you would have to configure the following properties:
S.N.Properties and Description
1hibernate.connection.datasource 
The JNDI name defined in the application server context you are using for the application.
2hibernate.jndi.class 
The InitialContext class for JNDI.
3hibernate.jndi. 
Passes any JNDI property you like to the JNDI InitialContext.
4hibernate.jndi.url 
Provides the URL for JNDI.
5hibernate.connection.username 
The database username.
6hibernate.connection.password 
The database password.

No comments:

Post a Comment