|
| 1 | +<?xml version='1.0' encoding='UTF-8' ?> |
| 2 | + |
| 3 | +<chapter xmlns="http://docbook.org/ns/docbook" |
| 4 | + xmlns:xl="http://www.w3.org/1999/xlink" |
| 5 | + xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 6 | + <title>OSGi Tutorial</title> |
| 7 | + |
| 8 | + <para> |
| 9 | + Hibernate targets the OSGi 4.3 spec or later and supports three types |
| 10 | + of configurations. |
| 11 | + |
| 12 | + <orderedlist> |
| 13 | + <listitem> |
| 14 | + <link xl:href="https://github.com/hibernate/hibernate-orm/tree/master/documentation/src/main/docbook/quickstart/tutorials/osgi/managed-jpa">Container-Managed JPA</link> |
| 15 | + </listitem> |
| 16 | + <listitem> |
| 17 | + <link xl:href="https://github.com/hibernate/hibernate-orm/tree/master/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-jpa">Unmanaged JPA</link> |
| 18 | + </listitem> |
| 19 | + <listitem> |
| 20 | + <link xl:href="https://github.com/hibernate/hibernate-orm/tree/master/documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native">Unmanaged Native</link> |
| 21 | + </listitem> |
| 22 | + </orderedlist> |
| 23 | + </para> |
| 24 | + |
| 25 | + <para> |
| 26 | + For more details about OSGi, the three configurations, hibernate-osgi, extensions points, and caveats, please |
| 27 | + see the OSGi chapter of the Developer's Guide! |
| 28 | + </para> |
| 29 | + |
| 30 | + <section> |
| 31 | + <title> |
| 32 | + Project Overview |
| 33 | + </title> |
| 34 | + <para> |
| 35 | + Each configuration has a QuickStart project located within the download bundle (under <filename>osgi</filename>). |
| 36 | + The bundles can be used as-is within Apache Karaf. Feel free to use them as literal |
| 37 | + "quick start" bundle templates. |
| 38 | + </para> |
| 39 | + </section> |
| 40 | + |
| 41 | + <section> |
| 42 | + <title> |
| 43 | + Project Structure |
| 44 | + </title> |
| 45 | + <itemizedlist> |
| 46 | + <listitem> |
| 47 | + <filename>osgi/datasource-h2.xml</filename>: Enterprise OSGi JPA usage can include a DataSource installed in the container. |
| 48 | + The client bundle's <literal>persistence.xml</literal> references the DataSource through JNDI. For an |
| 49 | + example, see how managed-jpa's <literal>persistence.xml</literal> calls out the |
| 50 | + <literal>jta-data-source</literal>. |
| 51 | + </listitem> |
| 52 | + <listitem> |
| 53 | + <filename>osgi/[project]/features.xml</filename>: This is arguably the most important "quick start" material. It defines |
| 54 | + a single Karaf feature ("hibernate-test") that demonstrates the necessary 3rd party libraries and |
| 55 | + bundle activation ordering. |
| 56 | + </listitem> |
| 57 | + <listitem> |
| 58 | + <filename>osgi/[project]/pom.xml</filename>: The POM includes typical compile-time dependencies (JPA, OSGi Core, |
| 59 | + OSGi Enterprise), as well as OSGi manifest data. |
| 60 | + </listitem> |
| 61 | + <listitem> |
| 62 | + <filename>osgi/[project]/src/main/resources/OSGI-INF/blueprint/blueprint.xml</filename>: |
| 63 | + The Blueprint includes container-managed EntityManager |
| 64 | + injection (for managed-jpa), as well as demonstrations showing how to register |
| 65 | + your custom implementations of Hibernate extension points. |
| 66 | + </listitem> |
| 67 | + <listitem> |
| 68 | + <filename>osgi/[project]/src/main/resources/META-INF/persistence.xml</filename> or |
| 69 | + <filename>osgi/[project]/src/main/resources/hibernate.cfg.xml</filename>: Note that the configurations |
| 70 | + are no different than typical uses of Hibernate! |
| 71 | + </listitem> |
| 72 | + <listitem> |
| 73 | + <filename>osgi/[project]/src/main/java/org/hibernate/osgitest/HibernateUtil.java</filename>: Demonstrates how to create an |
| 74 | + EntityManagerFactory (JPA) or SessionFactory (Native) using hibernate-osgi's services. Note that in |
| 75 | + managed-jpa, this is replaced by <literal>DataPointServiceImpl#entityManager</literal>, injected by |
| 76 | + <filename>blueprint.xml</filename> (described above). |
| 77 | + </listitem> |
| 78 | + </itemizedlist> |
| 79 | + </section> |
| 80 | + |
| 81 | + <section xml:id="hibernate-gsg-tutorial-envers-config"> |
| 82 | + <title> |
| 83 | + TODOs |
| 84 | + </title> |
| 85 | + <itemizedlist> |
| 86 | + <listitem> |
| 87 | + If using managed-jpa, <filename>features.xml</filename> will need the path to |
| 88 | + <filename>datasource-h2.xml</filename> updated. |
| 89 | + </listitem> |
| 90 | + </itemizedlist> |
| 91 | + </section> |
| 92 | + |
| 93 | + <section xml:id="hibernate-gsg-tutorial-envers-config"> |
| 94 | + <title> |
| 95 | + Karaf Commands |
| 96 | + </title> |
| 97 | + <para> |
| 98 | + All three bundles include Karaf Commands that can be used directly on the Karaf command line to test |
| 99 | + basic persistence operations ("dp:add [name]", "dp:getall", "dp:deleteall", etc.). I leave them in the |
| 100 | + QuickStarts as a useful sanity check. |
| 101 | + </para> |
| 102 | + </section> |
| 103 | + |
| 104 | +</chapter> |
0 commit comments