alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (tutorial_annotations.xml)

This example Hibernate source code file (tutorial_annotations.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

add, apis, developer, generatedvalue, guide, hibernate, hibernate, it, java, java, the, the, use, use

The Hibernate tutorial_annotations.xml source code

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">

<chapter id="hibernate-gsg-tutorial-annotations">
    <title>Tutorial Using Native Hibernate APIs and Annotation Mappings

    <para>
        This tutorial is located within the download bundle under <filename>basic.
    </para>
    <itemizedlist>
      <title>Objectives
      <listitem>
        <para>
          Use annotations to provide mapping information
        </para>
      </listitem>
      <listitem>
        <para>
          Use the <phrase>native Hibernate APIs
        </para>
      </listitem>
    </itemizedlist>


    <section id="hibernate-gsg-tutorial-annotations-config">
        <title>The Hibernate configuration file

        <para>
            The contents are identical to <xref linkend="hibernate-gsg-tutorial-basic-config"/>, with one important
            difference.  The <varname>mapping element at the very end naming the annotated entity class using
            the <option>class attribute.
        </para>
    </section>

    <section id="hibernate-gsg-tutorial-annotations-entity">
        <title>The annotated entity Java class
        <para>
            The entity class in this tutorial is <classname>org.hibernate.tutorial.annotations.Event which
            follows JavaBean conventions.  In fact the class itself is identical to the one in <xref
            linkend="hibernate-gsg-tutorial-basic-entity"/>, except that annotations are used to provide the metadata,
            rather than a separate <filename>hbm.xml file.
        </para>

        <example id="hibernate-gsg-tutorial-annotations-entity-entity">
            <title>Identifying the class as an entity
            <programlisting role="JAVA">@Entity
@Table( name = "EVENTS" )
public class Event {
    ...
}</programlisting>
        </example>

        <para>
          <!-- Is an entity an interface?? -->
          The <interfacename>@javax.persistence.Entity annotation is used to mark a class as an entity.
          It functions the same as the <varname>class mapping element discussed in  annotation explicitly specifies the table
          name. Without this specification, the default table name would be <literal>EVENT).