This document describes how to create a Hibernate Mapping File using NetBeans 6.1

After creating a project, right click on it and select New - other - Hibernate - Hibernate Mapping File as shown in the image below.


Selecting the Hibernate Mapping File type shows a brief description about it in the Description panel.

After selecting Hibernate Mapping File, press next button to bring up another wizard as shown below.


This wizard contains

  • File name, the name of the mapping file. Here empty and uniqueness of the file are checked.
            I.e, if the file already exists or the name of the file is empty then an error message will be
            shown at the bottom of the wizard panel.
  • Project, is a read only field, under which you want to create the mapping file.
  • Folder, by default set to src/java. But you can change the target folder by clicking the Browse button next to the text
            field to change the folder.
  • Created File, is a read only field, shows the location of the file.

Now press Next Button to select a mapping class..


This wizard contains

  • Class to Map, select a class by clicking ... button.
  • Configuration File, is a drop down with a list of configuration files in a project. By default the first entry is selected.
                     A mapping element is created in the selected configuration file when the finish button is pressed.
  • Database Table, lists all the tables from the database connection that is selected in the configuration file. This drop down is
                 automatically updated based on the selection of the configuration file drop down. The selection of Database Table
                 is optional. If selected, then an attribute with table is added to the class element.

After pressing the Finish button, a mapping file is created and placed under src/java.

The contents of the newly created mapping file look as shown below:

  <class dynamic-insert="false" dynamic-update="false" mutable="true" name="personClass" 
      optimistic-lock="version" polymorphism="implicit" select-before-update="false" 

The mapping element in the configuration file is as shown below:

  <session-factory name="session1">
    <property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
    <property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
    <property name="hibernate.connection.url">jdbc:derby://localhost:1527/travel</property>
    <property name="hibernate.connection.username">travel</property>
    <property name="hibernate.connection.password">travel</property>
    <mapping resource="hibernate.hbm.xml"/>

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo