| <?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="common-libraries"> |
| <title>Working with Common Enterprise Libraries</title> |
| <titleabbrev>Common Libraries</titleabbrev> |
| <section id="common-libraries-hibernate"> |
| <title>Working with Hibernate</title> |
| <section id="common-libraries-hibernate-import"> |
| <title>Importing Hibernate</title> |
| <para> |
| Hibernate uses CGLIB to dynamically create subclasses of your entity types at |
| runtime. To guarantee that Hibernate and CGLIB can correctly see the types, |
| you must add an <literal>Import-Library</literal> or <literal>Import-Bundle</literal> for the Hibernate library or bundle |
| into any bundle that uses Hibernate directly. |
| </para> |
| <para> |
| Additionally, if other bundles in your application contain types to be persisted by Hibernate, then be sure to specify the <code>import-scope</code> directive of the <literal>Import-Bundle</literal> header in the bundle that uses Hibernate directly. The <literal>import-scope</literal> directive tells @tomcat.product.name@ to implicitly import the bundle into all other bundles that make up the application; this ensures that bundles that indirectly depend on the generated Hibernate classes have access to them, but you do not have to explicitly update their <code>Import-Bundle</code> header, ensuring modularity. For example: |
| </para> |
| <programlisting> |
| Import-Bundle: com.springsource.org.hibernate;version="[3.2.6.ga,3.2.6.ga]";<emphasis role="bold">import-scope:=application</emphasis></programlisting> |
| <para> |
| The <code>import-scope</code> directive works only for the bundles in a scoped application (PARs or plans.) |
| </para> |
| |
| </section> |
| </section> |
| <section id="common-libraries-datasources"> |
| <title>Working with DataSources</title> |
| <para> |
| Many <literal>DataSource</literal> implementations use the <literal>DriverManager</literal> |
| class which is incompatible with typical OSGi class loading semantics. To get around this, |
| use a <literal>DataSource</literal> implementation that does not rely on |
| <literal>DriverManager</literal>. Versions of the following |
| <literal>DataSources</literal> that are known to work in an OSGi environment are available in the |
| <ulink url="http://www.springsource.com/repository">@ebr@</ulink>. |
| </para> |
| <itemizedlist> |
| <listitem> |
| <para> |
| <ulink url="http://www.springsource.com/repository/app/bundle/detail?name=com.springsource.org.apache.commons.dbcp">Apache Commons DBCP</ulink> |
| </para> |
| </listitem> |
| <listitem> |
| <para>SimpleDriverDataSource available in |
| <ulink url="http://www.springsource.com/repository/app/bundle/detail?name=org.springframework.jdbc">Spring JDBC</ulink> |
| 2.5.5 and later |
| </para> |
| </listitem> |
| </itemizedlist> |
| </section> |
| <section id="common-libraries-weaving-instrumentation"> |
| <title>Weaving and Instrumentation</title> |
| <para> |
| When using a library that performs bytecode weaving or instrumentation, such as AspectJ, |
| OpenJPA or EclipseLink, any types that are woven must be able to see the library doing |
| the weaving. This is accomplished by adding an <literal>Import-Library</literal> for the |
| weaving library into all bundles that are to be woven. |
| </para> |
| <para> |
| Weaving is often used by JPA implementations to transform persisted types. When using a |
| JPA provider that uses load-time weaving, an <literal>Import-Library</literal> for the |
| provider is needed in the bundles containing the persisted types. |
| </para> |
| </section> |
| <section id="common-libraries-tld"> |
| <title>JSP Tag Libraries</title> |
| <para> |
| When using tag libraries within a WAR or WAB, be sure to include an <literal>Import-Bundle</literal> |
| or <literal>Import-Library</literal> for the tag library bundle(s). This will ensure that your WAR or WAB |
| can see the TLD definition and implementing types. For example, to use the Apache implementation of JSTL, |
| add the following to your bundle’s <literal>/META-INF/MANIFEST.MF</literal>: |
| </para> |
| <programlisting> |
| <emphasis role="bold">Import-Bundle</emphasis>: com.springsource.org.apache.taglibs.standard;version="1.1.2" |
| </programlisting> |
| <para> |
| <literal>Import-Package</literal> can also be used but it is tedious to add all the imports as there are |
| typically lots of tld definitions in a bundle providing them. |
| </para> |
| </section> |
| </chapter> |