From hibernate-commits at lists.jboss.org Tue Aug 31 13:59:31 2010
Content-Type: multipart/mixed; boundary="===============8329380371290274033=="
MIME-Version: 1.0
From: hibernate-commits at lists.jboss.org
To: hibernate-commits at lists.jboss.org
Subject: [hibernate-commits] Hibernate SVN: r20292 - in
core/trunk/documentation/quickstart: src/main/docbook/en-US/content and 2
other directories.
Date: Tue, 31 Aug 2010 13:59:31 -0400
Message-ID: <201008311759.o7VHxVwv018502@svn01.web.mwc.hst.phx2.redhat.com>
--===============8329380371290274033==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Author: steve.ebersole(a)jboss.com
Date: 2010-08-31 13:59:31 -0400 (Tue, 31 Aug 2010)
New Revision: 20292
Added:
core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tutor=
ial_jpa.xml
Modified:
core/trunk/documentation/quickstart/src/main/docbook/en-US/Hibernate_Get=
ting_Started_Guide.xml
core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tutor=
ial_annotations.xml
core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tutor=
ial_native.xml
core/trunk/documentation/quickstart/tutorials/entitymanager/src/test/jav=
a/org/hibernate/tutorial/em/EntityManagerIllustrationTest.java
core/trunk/documentation/quickstart/tutorials/entitymanager/src/test/res=
ources/META-INF/persistence.xml
Log:
HHH-5445 - Write a jpa/entitymanager tutorial guide
Modified: core/trunk/documentation/quickstart/src/main/docbook/en-US/Hibern=
ate_Getting_Started_Guide.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/documentation/quickstart/src/main/docbook/en-US/Hibernate_Ge=
tting_Started_Guide.xml 2010-08-31 16:05:27 UTC (rev 20291)
+++ core/trunk/documentation/quickstart/src/main/docbook/en-US/Hibernate_Ge=
tting_Started_Guide.xml 2010-08-31 17:59:31 UTC (rev 20292)
@@ -31,6 +31,7 @@
+
=
\ No newline at end of file
Modified: core/trunk/documentation/quickstart/src/main/docbook/en-US/conten=
t/tutorial_annotations.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tuto=
rial_annotations.xml 2010-08-31 16:05:27 UTC (rev 20291)
+++ core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tuto=
rial_annotations.xml 2010-08-31 17:59:31 UTC (rev 20292)
@@ -30,7 +30,7 @@
=
-
+
The annotated entity Java class
The entity class in this tutorial is org.hibernate.=
tutorial.annotations.Event
@@ -39,7 +39,7 @@
annotations to provide the metadata instead of a separate hbm.xml file.
=
-
+
Identifying the class as an entity
@Entity
@Table( name =3D "EVENTS" )
@@ -57,7 +57,7 @@
EVENT).
=
-
+
Identifying the identifier property
@Id
@GeneratedValue(generator=3D"increment")
@@ -75,7 +75,7 @@
strategy for this entity's identifier values.
=
-
+
Identifying basic properties
public String getTitle() {
return title;
@@ -112,14 +112,15 @@
- With help of the Developer Guide, add an association t=
o the Event
- entity to model a message thread.
+ With help of the Developer=
Guide, add an association to
+ the Event entity to model a mes=
sage thread.
- With help of the Developer Guide, add a callback to re=
ceive notifications when an
- Event is created, updated or de=
leted. Try the same with an event listener.
+ With help of the Developer=
Guide, add a callback to
+ receive notifications when an Event is created, updated or deleted. Try =
+ the same with an event listener.
Added: core/trunk/documentation/quickstart/src/main/docbook/en-US/content/t=
utorial_jpa.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tuto=
rial_jpa.xml (rev 0)
+++ core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tuto=
rial_jpa.xml 2010-08-31 17:59:31 UTC (rev 20292)
@@ -0,0 +1,128 @@
+
+
+
+
+ Tutorial Using the Java Persistence API (JPA=
)
+
+
+ This tutorial is located within the download bundle under entitymanager and illustrates
+
+
+
+ using annotations to provide mapping information
+
+
+
+
+ using JPA
+
+
+
+
+
+
+ persistence.xml
+
+
+ The previous tutorials used the Hibernate-specific
+ hibernate.cfg.xml configuration file. JPA,
+ however, defines a different bootstrap proces=
s that uses its own configuration file
+ named persistence.xml. How this =
bootstrapping works is defined
+ by the JPA specification. In Java=
SE environments the
+ persistence provider (Hibernate in this case) is required to l=
ocate all JPA
+ configuration files by classpath lookup of the META-=
INF/persistence.xml resource
+ name.
+
+
+
+ persistence.xml
+
+
+ ...
+
+]]>
+
+
+
+ persistence.xml files should provide a un=
ique name for each
+ persistence unit. This name is how applicati=
ons reference the configuration
+ while obtaining an javax.persistence.EntityMana=
gerFactory reference.
+
+
+
+ The settings defined in the properties elem=
ent were already discussed in
+ . Here=
the javax.persistence-prefixed
+ varieties are used when possible. For the remaining Hibernate=
-specific configuration setting names notice
+ that they are now prefixed with hibernate..
+
+
+
+ Additionally, the class element functions t=
he same as discussed in
+ .
+
+
+
+
+ The annotated entity Java class
+
+ The entity is exactly the same as that from the annotations tu=
torial. See
+
+
+
+
+
+ Example code
+
+ The previous tutorials used the Hibernate APIs. This tutorial=
uses the JPA APIs.
+
+
+
+ Obtaining the javax.persistence.EntityMa=
nagerFactory
+ protected void setUp() throws Ex=
ception {
+ entityManagerFactory =3D Persistence.createEntityManagerFactory( "org.=
hibernate.tutorial.jpa" );
+}
+
+
+
+ Notice again the use of org.hibernate.tutorial.jpa as the
+ persistence unit name, which matches from
+
+
+
+ Saving (persisting) entities
+ EntityManager entityManager =3D =
entityManagerFactory.createEntityManager();
+entityManager.getTransaction().begin();
+entityManager.persist( new Event( "Our very first event!", new Date() ) );
+entityManager.persist( new Event( "A follow up event", new Date() ) );
+entityManager.getTransaction().commit();
+entityManager.close();
+
+
+
+ The code is pretty similar to . Here
+ we use an javax.persistence.EntityManager as opposed to a
+ org.hibernate.Session. JPA calls this operation
+ persist instead of save.
+
+
+
+ Obtaining a list of entities
+ result =3D entityManager.createQuery( "from Event", Event.clas=
s ).getResultList();
+for ( Event event : result ) {
+ System.out.println( "Event (" + event.getDate() + ") : " + event.getTi=
tle() );
+}
+entityManager.getTransaction().commit();
+entityManager.close();]]>
+
+
+
+ Again, the code is pretty similar to .
+
+
+
+
\ No newline at end of file
Modified: core/trunk/documentation/quickstart/src/main/docbook/en-US/conten=
t/tutorial_native.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tuto=
rial_native.xml 2010-08-31 16:05:27 UTC (rev 20291)
+++ core/trunk/documentation/quickstart/src/main/docbook/en-US/content/tuto=
rial_native.xml 2010-08-31 17:59:31 UTC (rev 20292)
@@ -320,8 +320,8 @@
- With help of the Developer Guide, add an association t=
o the Event
- entity to model a message thread.
+ With help of the Developer=
Guide, add an association to
+ the Event entity to model a mes=
sage thread.
Modified: core/trunk/documentation/quickstart/tutorials/entitymanager/src/t=
est/java/org/hibernate/tutorial/em/EntityManagerIllustrationTest.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/documentation/quickstart/tutorials/entitymanager/src/test/ja=
va/org/hibernate/tutorial/em/EntityManagerIllustrationTest.java 2010-08-31 =
16:05:27 UTC (rev 20291)
+++ core/trunk/documentation/quickstart/tutorials/entitymanager/src/test/ja=
va/org/hibernate/tutorial/em/EntityManagerIllustrationTest.java 2010-08-31 =
17:59:31 UTC (rev 20292)
@@ -42,7 +42,8 @@
@Override
protected void setUp() throws Exception {
// like discussed with regards to SessionFactory, an EntityManagerFactor=
y is set up once for an application
- entityManagerFactory =3D Persistence.createEntityManagerFactory( "hibern=
ate-jpa-tutorial" );
+ // IMPORTANT: notice how the name here matches the name we gave the pe=
rsistence-unit in persistence.xml!
+ entityManagerFactory =3D Persistence.createEntityManagerFactory( "org.hi=
bernate.tutorial.jpa" );
}
=
@Override
Modified: core/trunk/documentation/quickstart/tutorials/entitymanager/src/t=
est/resources/META-INF/persistence.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/documentation/quickstart/tutorials/entitymanager/src/test/re=
sources/META-INF/persistence.xml 2010-08-31 16:05:27 UTC (rev 20291)
+++ core/trunk/documentation/quickstart/tutorials/entitymanager/src/test/re=
sources/META-INF/persistence.xml 2010-08-31 17:59:31 UTC (rev 20292)
@@ -26,7 +26,7 @@
xsi:schemaLocation=3D"http://java.sun.com/xml/ns/persistence =
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version=3D"2.0">
=
-
+
Persistence unit for the JPA tutorial of the Hibernate Getting=
Started Guide
--===============8329380371290274033==--