Hibernate 5 configuration dtd

In Hibernate 5 configuration dtd is different from Hibernate 4, in this example we will see how use Hibernate 5 configuration dtd

Hibernate 5 configuration dtd Example

In Hibernate 5 dtd is different from previous version of Hibernate. Hibernate dtd comes included with the Hibernate jar file. In Hibernate 5 we will have to use the latest of DTD in the hibernate.cfg.xml file.

What is Hibernate Configuration file?

To use Hibernate we have to provide certain parameters which is used by Hibernate ORM framework to bootstrap the system correctly. We have to provide following informations:

  • DTD to be used - This is used to validate the hibernate.cfg.xml file data. In Hibernate 5 we have to use hibernate-configuration-5.0.dtd file.
     
  • Database Driver - Database driver class to be used for connecting to database
     
  • Connection url - URL of the database server
     
  • User name: Database username
     
  • Password: Password of database
     
  • Hibernate dialect class - Hibernate provides separate dialect classes for each database. We have to select the dialect which is compatible for your database

After providing all these information Hibernate will be able to instantiate ORM system at application startup.

Example of hibernate.cfg file

In Hibernate 5 you should use correct dtd configuration. Following hibernate.cfg file shows how to include Hibernate 5 dtd correctly:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-5.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate5</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.current_session_context_class">thread</property>

<mapping class="net.roseindia.model.Employee" />

</session-factory>
</hibernate-configuration>

So, you learned the correct way to configure dtd in Hibernate 5 application. Explore following tutorials of Hibernate 5:

Advertisements

 

We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+

Hibernate 5 configuration dtd

Posted on: October 14, 2017 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Hibernate 5 configuration dtd  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads