diff --git a/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/annotations/hibernate.cfg.xml b/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/annotations/hibernate.cfg.xml new file mode 100644 index 0000000000..7e862fd562 --- /dev/null +++ b/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/annotations/hibernate.cfg.xml @@ -0,0 +1,36 @@ + + + + + + + + + org.h2.Driver + jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE + sa + + + + 1 + + + org.hibernate.dialect.H2Dialect + + + org.hibernate.cache.NoCacheProvider + + + true + + + update + + + + + + + \ No newline at end of file diff --git a/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/annotations/org/hibernate/tutorial/annotations/Event.java b/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/annotations/org/hibernate/tutorial/annotations/Event.java new file mode 100644 index 0000000000..811e5c17ad --- /dev/null +++ b/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/annotations/org/hibernate/tutorial/annotations/Event.java @@ -0,0 +1,47 @@ +package org.hibernate.tutorial.annotations; + +import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Table( name = "EVENTS" ) +public class Event { + private Long id; + + private String title; + private Date date; + + public Event() {} + + @Id + public Long getId() { + return id; + } + + private void setId(Long id) { + this.id = id; + } + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "EVENT_DATE") + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} \ No newline at end of file diff --git a/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/annotations/pom.xml b/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/annotations/pom.xml new file mode 100644 index 0000000000..ff94d1f3fe --- /dev/null +++ b/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/annotations/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + org.hibernate.tutorials + hibernate-tutorial-annotations + 1.0.0-SNAPSHOT + Hibernate Annotations Tutorial + + + + org.hibernate + hibernate-core + + + + + org.slf4j + slf4j-simple + + + + + javassist + javassist + + + + + com.h2database + h2 + + + + \ No newline at end of file diff --git a/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/hbm/hibernate.cfg.xml b/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/hbm/hibernate.cfg.xml index 11396f4a8f..212273b65f 100644 --- a/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/hbm/hibernate.cfg.xml +++ b/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/hbm/hibernate.cfg.xml @@ -28,7 +28,7 @@ update - + diff --git a/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/hbm/org/hibernate/tutorial/hbm/Event.hbm.xml b/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/hbm/org/hibernate/tutorial/hbm/Event.hbm.xml index e305e7177c..9b73df75ab 100644 --- a/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/hbm/org/hibernate/tutorial/hbm/Event.hbm.xml +++ b/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/hbm/org/hibernate/tutorial/hbm/Event.hbm.xml @@ -1,4 +1,3 @@ - @@ -10,4 +9,3 @@ -]]> diff --git a/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/hbm/pom.xml b/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/hbm/pom.xml index f9b1d46027..fa2c134bbd 100644 --- a/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/hbm/pom.xml +++ b/documentation/quickstart/src/main/docbook/en-US/content/extras/examples/hbm/pom.xml @@ -1,50 +1,37 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> -4.0.0 + 4.0.0 -org.hibernate.tutorials -hibernate-tutorial-native -1.0.0-SNAPSHOT -Hibernate Native Tutorial + org.hibernate.tutorials + hibernate-tutorial-hbm + 1.0.0-SNAPSHOT + Hibernate hbm.xml Tutorial - - - ${artifactId} - + + + org.hibernate + hibernate-core + - - - org.hibernate - hibernate-core - + + + org.slf4j + slf4j-simple + - - - javax.servlet - servlet-api - + + + javassist + javassist + - - - org.slf4j - slf4j-simple - - - - - javassist - javassist - - - - - com.h2database - h2 - - + + + com.h2database + h2 + + -]]> \ No newline at end of file diff --git a/documentation/quickstart/src/main/docbook/en-US/content/tutorial_annotations.xml b/documentation/quickstart/src/main/docbook/en-US/content/tutorial_annotations.xml index 46fd6944cf..bc5825c647 100644 --- a/documentation/quickstart/src/main/docbook/en-US/content/tutorial_annotations.xml +++ b/documentation/quickstart/src/main/docbook/en-US/content/tutorial_annotations.xml @@ -2,16 +2,107 @@ - Tutorial Using Native Hibernate APIs and annotations + Tutorial Using Native Hibernate APIs and Annotation Mappings - - This tutorial introduces some key concepts of the native Hibernate API. - - - + + Steps + + + Create the Maven POM file - + Create a file named pom.xml in the root of your project directory, containing + the text in. - - + + + <filename>pom.xml</filename> + + + + + + + Create the annotated entity Java class + + + Create a file namedsrc/main/java/org/hibernate/tutorial/annotations/Event.java, + containing the text in. + + + + + <filename>Entity.java</filename> + + + + + + Notes About the Entity + + + The entity class is still using JavaBean conventions. In fact the class itself is exactly + the same as we saw in , the only + difference being the use of annotations to provide the metadata instead of a separate + hbm.xml file. + + + + + The @javax.persistence.Entity annotation is used to mark a + class as an entity. It's function is essentially the same as the class + mapping element we see in . + Additionally the @javax.persistence.Table annotation is + used to override the default table name annotations would have used (EVENT). + + + + + @javax.persistence.Id marks the property defining the + entity's identifier. + + + + Property-related annotations are allowed on either the field or the getter method. + However, for a given entity they cannot be mixed. The placement of the + @javax.persistence.Id indicates where Hibernate + should expect to find other property-related annotations. + + + + + + + Just as in , the + date property needs special handling to account for its special naming + and its SQL type. + + + + + + + + Create the Hibernate configuration file + + + Create a file named src/main/resources/hibernate.cfg.xml with the following contents: + + + + <filename>hibernate.cfg.xml</filename> + + + + + Most of the contents are exactly the same as in . + The single difference is the mapping element at the very end naming the + annotated entity class using the class attribute. + + + + + + + + \ No newline at end of file diff --git a/documentation/quickstart/src/main/docbook/en-US/content/tutorial_native.xml b/documentation/quickstart/src/main/docbook/en-US/content/tutorial_native.xml index ae6efd881b..a833dae129 100644 --- a/documentation/quickstart/src/main/docbook/en-US/content/tutorial_native.xml +++ b/documentation/quickstart/src/main/docbook/en-US/content/tutorial_native.xml @@ -2,13 +2,11 @@ - Tutorial Using Native Hibernate APIs and <filename>hbm.xml</filename> mappings + Tutorial Using Native Hibernate APIs and <filename>hbm.xml</filename> Mappings - This tutorial uses the - standard layout - described in + This tutorial uses the standard layout described in .