Configure MySql Database With Hibernate Mappings

Configure MySql Database

Configuring MySql database with hibernate is the same as with other databasses. The only difference will be connection url and the database dialect to be specified in the configuration file. This tips provides a basic example configuration file for configuaring the MySql with hibernate. But it doesn’t explain you installing the MySql database. If you are looing for installing MySql database please read it here : http://dev.mysql.com/downloads/

also read:

Sample URL is jdbc:mysql://localhost:3306/SampleDB. In this URL port 3306 is default for the mysql database. If you are not specifying that in the URL, it will assume the port is 3306.localhost can be replaced with your system IP address and machine name.SampleDB is the database or catelog name you have created. Every session factory can have only one database. if you want to use multiple database, create multiple session factory with different database names.

org.hibernate.dialect.MySQLDialect (Read: List of Hibernate Dialects) is the dialect name for MySQL database. Each database has its own dialect declared in the hibernate package.

<?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>
        <!-- Database connection settings -->
        <property name='connection.driver_class'>com.mysql.jdbc.Driver</property>
        <property name='connection.url'>jdbc:mysql://localhost:3306/SampleDB</property>
        <property name='connection.username'>root</property>
        <property name='connection.password'>root</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name='connection.pool_size'>1</property>

        <!-- SQL dialect -->
        <property name='dialect'>org.hibernate.dialect.MySQLDialect</property>

        <!-- Echo all executed SQL to stdout -->
        <property name='show_sql'>true</property>

        <!-- Mapping files -->
        <mapping resource='Author.hbm.xml'/>
    </session-factory>
</hibernate-configuration>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Pin It on Pinterest

Share This

Share this post with your friends!

Share This

Share this post with your friends!