Tell a friend
Link to us
Bookmark Us
Total Members
      Members: 87081
Sitemap Forum Chat
 
Java Home
Java Members (28736)
Java Member Articles ( 41 )
Java Discussion (283)
Java Q & A ( 172 )
- Java Ask Question
- Java Questions
- Java Unanswered Questions
Java Resources
Java Source Code (1096)
Java Articles (552)
Java Blogs (133)
Java Jobs (801)
Java Components (85)
Java Books (169)
Java Websites (127)
Java News (103)

 
Resource Directory
Java Hosting (0)
Source Code (0)

 
GROUP INFO
Members: 28736
Access Type: Anyone can join

 

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
LINQ Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Javascript Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Grails Tutorial
Hibernate Tutorial
Java 1.6 Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Service-Oriented Architecture (SOA) Tutorial For Managers
Spring Tutorial
Struts Tutorial
Tomcat Tutorial

RESOURCES
Q & A (531 )
Source Code (3276 )
Articles (365 )
Books (373 )
Components (1647 )
News (898 )
Websites (1208 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Authors
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Feedback
Tell a Friend
Advertise

 

Home > Java > Member Articles > Database >
 

Hibernate Tutorial


  Author : VisualBuilder.com
  Date Published : 05/13/2007
  Accessed : 21275
   visualbuilder
<< Back  Next >> 

Now it is the time to create our Hibernate configuration file. This file will contain the hibernate session configuration like the database driver,user name and password or a JNDI data source if you would like to use one,cache provider ad other session parameters. Also this file contains the entries for Object to Relation mapping that we will create later. Initially let's create the file with minimum required information and understand what does that information mean.


Create a new file hibernate.cfg.xml in src folder and add the following contents to this file.


<?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="connection.url">
          jdbc:oracle:thin:@localhost:1521:XE
        </property>
        <property name="connection.driver_class">
          oracle.jdbc.driver.OracleDriver
        </property>
        <property name="connection.username">
          SYSTEM
        </property>
        <property name="connection.password">
          manager
        </property>
        <!-- Set AutoCommit to true -->
        <property name="connection.autocommit">
          true
        </property>
        <!-- SQL Dialect to use. Dialects are database specific -->
        <property name="dialect">
          org.hibernate.dialect.OracleDialect
        </property>
        <!-- Mapping files -->
        <mapping resource="com/visualbuilder/hibernate/User.hbm.xml" />
      </session-factory>
    </hibernate-configuration>



As you can see,the session factory configuration is set of few properties required for a database connection. connection.url is the JDBC URL required to connect to the database. connection.driver_class is the JDBC Driver class which we normally use in Class.forName while establishing a connection to the database. connection.username and connection.password are the database user name and password respectively. connection.autocommit sets the Autocommit property of the underlying connection. We have set it to true so that we don't need to commit the transactions ourselves unless we want to do it intentionally.


This configuration is for an Oracle database at my machine. If you are unaware of how to build a URL for an Oracle database,note that the you need to replace XE with an appropriate SID of your Oracle database,localhost with the IP address of the machine where Oracle is running if not on local machine,and 1521 with the port. In most cases,you will only change the SID and rest of the parameters will remain the same.


If you are using MySQL,you should put the appropriate URL,Driver class name,user name,password and the Dialect name. The Dialect for MySQL is org.hibernate.dialect.MySQLDialect. Driver class for the MySQL is com.mysql.jdbc.Driver and the URL for MySQL is jdbc:mysql://<server>:<port>/<database-name>. The default port for MySQL is 3306.


The next important step is to add the JDBC driver jar file to the project libraries just like we added the struts libraries. For oracle,it is ojdbc14.zip or ojdbc14.jar and can be found under Oracle installation/jdbc/lib. For example,if Oracle XE is installed in C:\oraclexe,the ojdbc14.jar can be found on the following path. C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib. You can also download it from http://www.minq.se/products/dbvis/drivers.html freely.You can download the MySQL JDBC driver freely from http://dev.mysql.com/downloads/connector/j/5.0.htmll


 


Pages   << Back  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  Next >>  Next: Part 11: Writing the first Java File >>

 
   Printer Friendly
   Email to a friend
   Add to my Favourites  Report Bad Submissions  Submit Feedback
  Download PDF version
 
                 Click each image to add
this page to each site.
 
Related Articles of Java
Previous Article    -     Random Articles    -     Next Article
 
 
 
 
 
 
 
 
Welcome Guest Signup
Member's Panel
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!

SEARCH
 



 
 
 
 
 


Home | Login | About Us | Contact Us | Privacy Policy | Advertising | Feedback Please

Warning: Unknown(): write failed: Disk quota exceeded (122) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0