Author: steve.ebersole(a)jboss.com
Date: 2010-08-31 09:03:19 -0400 (Tue, 31 Aug 2010)
New Revision: 20287
Modified:
core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tutorial_annotations.xml
Log:
HHH-5444 - Write annotations tutorial chapter
Modified:
core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tutorial_annotations.xml
===================================================================
---
core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tutorial_annotations.xml 2010-08-31
12:43:29 UTC (rev 20286)
+++
core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tutorial_annotations.xml 2010-08-31
13:03:19 UTC (rev 20287)
@@ -34,44 +34,65 @@
<title>The annotated entity Java class</title>
<para>
The entity class in this tutorial is
<classname>org.hibernate.tutorial.annotations.Event</classname>
- <itemizedlist>
- <title>Notes About the Entity</title>
- <listitem>
- <para>
- The entity class is still using JavaBean conventions. In fact
the class itself is exactly
- the same as we saw in <xref
linkend="hibernate-gsg-tutorial-basic-entity"/>, the only
- difference being the use of annotations to provide the metadata
instead of a separate
- <filename>hbm.xml</filename> file.
- </para>
- </listitem>
- <listitem>
- <para>
- The
<interfacename>(a)javax.persistence.Entity</interfacename> annotation is used to
mark a
- class as an entity. It's function is essentially the same as
the <literal>class</literal>
- mapping element discussed in <xref
linkend="hibernate-gsg-tutorial-basic-mapping"/>.
- Additionally the
<interfacename>(a)javax.persistence.Table</interfacename> annotation is
- used to explicitly specify the table name (the default table name
would have been
- <database class="table">EVENT</database>).
- </para>
- </listitem>
- <listitem>
- <para>
- <interfacename>(a)javax.persistence.Id</interfacename>
marks the property defining the
- entity's identifier.
<interfacename>(a)javax.persistence.GeneratedValue</interfacename> and
-
<interfacename>(a)org.hibernate.annotations.GenericGenerator</interfacename>
work in tandem
- to indicate that Hibernate should use Hibernate's
<literal>increment</literal> generation
- strategy for this entity's identifier values.
- </para>
- </listitem>
- <listitem>
- <para>
- Just as discussed in <xref
linkend="hibernate-gsg-tutorial-basic-mapping"/>, the
- <literal>date</literal> property needs special
handling to account for its special naming
- and its SQL type.
- </para>
- </listitem>
- </itemizedlist>
+ which is still following JavaBean conventions. In fact the class itself is
exactly the same as we saw
+ in <xref linkend="hibernate-gsg-tutorial-basic-entity"/>, the
only difference being the use of
+ annotations to provide the metadata instead of a separate
<filename>hbm.xml</filename> file.
</para>
+
+ <example id="hibernate-gsg-tutorial-basic-entity-entity">
+ <title>Identifying the class as an entity</title>
+ <programlisting role="JAVA">@Entity
+@Table( name = "EVENTS" )
+public class Event {
+ ...
+}</programlisting>
+ </example>
+
+ <para>
+ The <interfacename>(a)javax.persistence.Entity</interfacename>
annotation is used to mark a
+ class as an entity. It's function is essentially the same as the
<literal>class</literal>
+ mapping element discussed in <xref
linkend="hibernate-gsg-tutorial-basic-mapping"/>.
+ Additionally the
<interfacename>(a)javax.persistence.Table</interfacename> annotation is
+ used to explicitly specify the table name (the default table name would have
been
+ <database class="table">EVENT</database>).
+ </para>
+
+ <example id="hibernate-gsg-tutorial-basic-entity-id">
+ <title>Identifying the identifier property</title>
+ <programlisting role="JAVA">@Id
+@GeneratedValue(generator="increment")
+@GenericGenerator(name="increment", strategy = "increment")
+public Long getId() {
+ return id;
+}</programlisting>
+ </example>
+
+ <para>
+ <interfacename>(a)javax.persistence.Id</interfacename> marks the
property defining the
+ entity's identifier.
<interfacename>(a)javax.persistence.GeneratedValue</interfacename> and
+
<interfacename>(a)org.hibernate.annotations.GenericGenerator</interfacename>
work in tandem
+ to indicate that Hibernate should use Hibernate's
<literal>increment</literal> generation
+ strategy for this entity's identifier values.
+ </para>
+
+ <example id="hibernate-gsg-tutorial-basic-entity-properties">
+ <title>Identifying basic properties</title>
+ <programlisting role="JAVA">public String getTitle() {
+ return title;
+}
+
+(a)Temporal(TemporalType.TIMESTAMP)
+@Column(name = "EVENT_DATE")
+public Date getDate() {
+ return date;
+}</programlisting>
+ </example>
+
+ <para>
+ Just as discussed in <xref
linkend="hibernate-gsg-tutorial-basic-mapping"/>, the
+ <literal>date</literal> property needs special handling to
account for its special naming
+ and its SQL type.
+ </para>
</section>
<section id="hibernate-gsg-tutorial-annotations-test">
Show replies by thread