<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Sahoo&apos;s Blog</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/" />
<modified>2008-05-12T19:25:31Z</modified>
<tagline></tagline>
<id>tag:weblogs.java.net,2008:/blog/ss141213/298</id>
<generator url="http://www.movabletype.org/" version="3.01D">Movable Type</generator>
<copyright>Copyright (c) 2008, ss141213</copyright>
<entry>
<title>Updated instructions to use OpenJPA in GlassFish</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2008/05/updated_instruc.html" />
<modified>2008-05-12T19:25:31Z</modified>
<issued>2008-05-12T19:23:37Z</issued>
<id>tag:weblogs.java.net,2008:/blog/ss141213/298.9782</id>
<created>2008-05-12T19:23:37Z</created>
<summary type="text/plain">Layout of OpenJPA installation has changed since I last blogged about using OpenJPA in GlassFish, so many users who are unaware of this difference face some trouble while using OpenJPA in GlassFish. I thought of updating the instructions; hence this blog.</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p>Layout of OpenJPA installation has changed since I last blogged about using OpenJPA in GlassFish. Let's say one installs OpenJPA in a directory called ${OPENJPA_HOME}. Earlier (I am talking about the days when OpenJPA was still in Apache incubator), all the jars would live under <em>${OPENJPA_HOME}/lib</em> directory. Now, things have changed. The primary artifact, openjpa-${version}.jar, which contains classes built out of OpenJPA codebase lives under ${OPENJPA_HOME}; where as all the other library jars live under ${OPENJPA_HOME}/lib. So, all you need to do is to copy the appropriate jars like this:<br />
<pre> cp ${OPENJPA_HOME}/openjpa*.jar ${OPENJPA_HOME}/lib/*.jar ${GLASSFISH_HOME}/domains/domain1/lib </pre><br />
and restart GlassFish. For further information, please refer to <a href="http://weblogs.java.net/blog/ss141213/archive/2006/07/using_openjpa_a.html">my earlier blog</a>. I have updated that blog as well.</p>

<p>For issues, please don't hesitate to contact us at <u>users (at) glassfish.dev.java.net</u></p>]]>

</content>
</entry>
<entry>
<title>Bug in Bundle.getResource() in Knopflerfish?</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2008/05/bug_in_bundlege.html" />
<modified>2008-05-01T08:38:58Z</modified>
<issued>2008-05-01T08:38:52Z</issued>
<id>tag:weblogs.java.net,2008:/blog/ss141213/298.9651</id>
<created>2008-05-01T08:38:52Z</created>
<summary type="text/plain">I observed some difference in behavior while running an OSGi test case on Knopflerfish, and decided to investigate further. Here is the outcome...</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p>I was running a simple test on multiple OSGi platforms. I am seeing some difference in behavior when I run it on Knopflerfish #2.0.3. Upon investigation, I observed that Bundle.getResource() implementation on Knopflerfish does not use the parent class loader of the bundle even when I set <strong>org.osgi.framework.bootdelegation=*</strong>. </p>

<p>Here is a simple code that I used to test my theory:<br />
<pre>public class Activator implements BundleActivator{</p>

<p>    public void start(BundleContext context) throws Exception {<br />
        Class libClazz = context.getBundle().loadClass("sahoo.Library");<br />
        System.out.println("libClazz = " + libClazz);<br />
        URL libRes = context.getBundle().getResource("sahoo/Library.class");<br />
        System.out.println("libRes = " + libRes);<br />
    }<br />
...</pre></p>

<p>The above code prints non-null value for libClazz, but a null value for libResource. <u>If Bundle.loadClass("sahoo.Library") could load the class, how could Bundle.getResource("sahoo/Library.class") return null?</u> It works as expected in other OSGi implementations.</p>

<p>To ensure that sahoo.Library.class is available in the parent class loader, I wrote a Main class which creates a ClassLoader that has both the knopflerfish framework.jar and my library.jar in search path. I then use that classloader to launch knopflerfish.</p>

<p>Has anyone else faced similar issues? I think this is a serious bug in knopflerfish. I tried to get a confirmation by <a href="https://sourceforge.net/forum/forum.php?thread_id=2024156&forum_id=328005">reporting it in their forum</a>, but no luck. I also tried using the <a href="https://sourceforge.net/forum/forum.php?thread_id=2024247&forum_id=385235">dev forum</a>, but no difference. Is there a better way to ask them questions? I don't know. So I thought I would document what I observed.</p>]]>

</content>
</entry>
<entry>
<title>GlassFish V3 on OSGi - Part I</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2008/04/glassfish_v3_on.html" />
<modified>2008-04-16T03:56:31Z</modified>
<issued>2008-04-16T03:56:21Z</issued>
<id>tag:weblogs.java.net,2008:/blog/ss141213/298.9545</id>
<created>2008-04-16T03:56:21Z</created>
<summary type="text/plain">We have put back initial code that enables GlassFish V3 to run on an *OSGi* R4 platform. This is in addition to it being able to run on its own runtime, i.e., HK2. Since I have been involved in this effort from the very beginning, I will be blogging about it in days to come. Today is just the start.</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p>I guess by now you have heard the big news coming out of GlassFish community.  We have put back initial code that enables <a href="http://GlassFish.dev.java.net"> GlassFish</a> to run on an *OSGi* R4 platform. <a href="http://felix.apache.org">Felix</a> is currently our default OSGi runtime. I am assuming you have either read <a href="http://blogs.sun.com/dochez/entry/glassfish_v3_runs_on_osgi">Jerome's blog</a> or <a href="http://blogs.sun.com/theaquarium/entry/glassfish_v3_now_with_osgi"> Eduardo's posting in The Aquarium</a>. If you have not, I suggest you read them first. Jerome and Eduardo have explained some of the rational behind this change and what to expect in coming days. Now some details not covered there:</p>

<p>The following picture tries to give an idea as to how the runtime looks like when GlassFish is running on an OSGi platform:</p>

<p><img alt="GFOnOSGiDiagram.png" src="http://weblogs.java.net/blog/ss141213/archive/gfv3osgi-1/GFOnOSGiDiagram.png" width="386" height="325" align="CENTRE" /></p>

<p><strong>All</strong> our GlassFish modules including the <strong>Java EE APIs</strong> are packaged as OSGi bundles. Some of you may wonder what's HK2's role here. <a href="http://HK2.dev.java.net">HK2</a> has following layers, viz:<br />
<strong>module layer</strong> - responsible for class loading and life cycle management<br />
<strong>component layer</strong> - which is responsible for component registration, injection, outjection, etc.<br />
<strong>config layer</strong> - responsible for configuring components by reading data from XML file. The XML file can be transactionally updated to reflect changes in component.<br />
A simple class diagram that shows some of the HK2 abstractions (except those of config layer) is shown below:<br />
<img alt="HK2Model.jpg" src="http://weblogs.java.net/blog/ss141213/archive/gfv3osgi-1/HK2Model.jpg" width="881" height="511" /></p>

<p>We have implemented HK2' module layer APIs on OSGi by delegating to OSGi module layer. HK2's component layer and config layer relies on HK2's module APIs. Once those APIs are available, it is not that difficult to make those two layers available as OSGi bundles. Except for cases like URLStreamHandler registration, GlassFish modules do not use OSGi APIs directly; they use HK2 module APIs which are available on both the runtimes. That allows them to run unchanged on both the runtimes. Some other day, I shall talk about the <strong>service mapper</strong>.</p>

<p>Last, but not the least, I want to thank <a href="http://Felix.apache.org">Felix</a> community for the excellent support that they provide in their forum. It's not just the framework that I found easy to use. Their <a href="http://felix.apache.org/site/maven-bundle-plugin-bnd.html">maven-bundle-plugin</a>, which wraps Peter Krien's <a href="http://www.aqute.biz/Code/Bnd">bnd</a> tool, makes life of maven users so much easier.</p>

<p>Now, before you ask me, let me preempt you:</p>

<p><u>Why did we take this approach?</u><br />
A lot of GlassFish code was already written, so we wanted an easier migration path without disrupting our schedule.</p>

<p><u>What are the benefits of this approach?</u><br />
Well, it allows us to experiment on both the modes. Theoretically, given another compatible module system, we can switch to using that with relative ease.</p>

<p><u>What are the drawbacks of this approach?</u><br />
By limiting ourselves to HK2 APIs, we are not able to take advantage of rich module management APIs that OSGi provides.</p>

<p><u>Will we continue to support both the modes?</u><br />
Not very long. But, that does not mean that HK2 will vanish. As Jerome explains in his blog, HK2 will continue to provide component layer and config layer.</p>

<p><u>How does GlassFish use bundle repository?</u><br />
That is something I have to investigate next.</p>

<p><u>What other OSGi implementation does it run on?</u><br />
Theoretically speaking, since our code is written against R4 spec, it should run in any compliant implementation - it's a matter of configuration I would say. We have tried all major three and it works. More on this to follow in time to come. Felix is currently our default platform - it is distributed as part of our runtime.</p>

<p><u>What's next?</u><br />
This is just the beginning. We have so many things lined up in this area. I have a long TODO list which I have to prioritize. We hope you shall provide constructive feedback to make it better. As Eduardo mentioned in his blog, please wait for the builds to stabilize. </p>]]>

</content>
</entry>
<entry>
<title>Getting started with HK2 - Part II</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2008/01/getting_started_1.html" />
<modified>2008-01-30T04:39:51Z</modified>
<issued>2008-01-28T20:29:35Z</issued>
<id>tag:weblogs.java.net,2008:/blog/ss141213/298.9084</id>
<created>2008-01-28T20:29:35Z</created>
<summary type="text/plain">As promised in my last blog, in this blog I am going to expand our Hello World sample to demonstrate module management, class loading, component injection features in HK2.</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p><a href="http://weblogs.java.net/blog/ss141213/examples/2nd-hello-world-hk2-sample.zip">Download The Sample</a></p>

<p>This is a sequel to <a href="http://weblogs.java.net/blog/ss141213/archive/2008/01/getting_started.html">my last blog</a> where I described a Hello World sample running on HK2. As promised there, I am going to expand that sample to show module management, class loading, component injection, instantiation cascading features of HK2 working. </p>

<p><u><strong>Structure of the sample</strong></u><br />
<pre><br />
hello-world-hk2-sample2/<br />
                       /pom.xml<br />
                       /hello2-startup/pom.xml<br />
                                    /src/main/java/sahoo/hello/startup/MyStartup.java<br />
                       /hello2-impl/pom.xml<br />
                                   /src/main/java/sahoo/hello/api/Foo.java<br />
                                   /src/main/java/sahoo/hello/api/Bar.java<br />
                                   /src/main/java/sahoo/hello/impl/FooImpl.java<br />
                                   /src/main/java/sahoo/hello/impl/BarImpl.java<br />
</pre></p>

<p>The modules are organized the same way as our earlier example except that I have added a new module called hello2-impl. The new module holds some implementation details. It is introduced to show how inter-module dependency is managed by HK2.</p>

<p>Instructions to build and run remain unchanged. You can run <em>mvn -f hello-world-hk2-sample-2/pom.xml install</em> to build the sample. To run it, do one of the following:<br />
mvn -f hello-world-hk2-sample-2/hello2-startup/pom.xml hk2:run<br />
or<br />
hello-world-hk2-sample-2/run.sh <br />
Refer to the earlier blog for an explanation of the above steps.</p>

<p>Let's go through the contents, first our new module, hello-impl. <br />
<u><strong>Step 1. Make it a HK2 module:</strong></u><br />
To do this, we need to specify packaging type as hk2-jar in its <a href="http://weblogs.java.net/blog/ss141213/examples/2nd-hello-world-hk2-sample/hello2-impl/pom.xml.txt">pom.xml</a>. Since this is a custom packaging type, we need to configure the pom.xml with the plugin, hk2-maven-plugin, which provides such support. Since this plugin as well as HK2 modules are not available in standard Maven repo, you have to configure some extra repositories in the <a href="http://weblogs.java.net/blog/ss141213/examples/2nd-hello-world-hk2-sample/pom.xml.txt">parent POM</a> (you can do it in your ~/.m2/settings.xml as well, if you want to avoid doing it every time).</p>

<p><u><strong>Step 2: Choose the packages you want to export:</strong></u><br />
Next, let's see how to choose the packages we want to export. <em>By default, HK2 module management exports all packages from a module to other modules.</em> This is just opposite to how <strong>OSGi</strong> behaves. hello2-impl module has two packages, viz: sahoo.hello.api and sahoo.hello.impl. The former one contains interfaces that we would like to export, where as the latter one contains implementation details that we would like to hide from others. Currently, there is no package level annotations defined in HK2 to mark some packages for exporting, hence we have to manually configure our hk2-maven-plugin in pom.xml to generate the following manifest entry:<br />
<strong>HK2-Export-Package: sahoo.hello.api</strong><br />
It is achieved by configuring the hk2-maven-plugin in pom.xml as follows:<br />
<pre><br />
    &lt;build&gt;<br />
        &lt;plugins&gt;<br />
            &lt;plugin&gt;<br />
                &lt;groupId&gt;com.sun.enterprise&lt;/groupId&gt;<br />
                &lt;artifactId&gt;hk2-maven-plugin&lt;/artifactId&gt;</p>

<p>                &lt;version&gt;...&lt;/version&gt;<br />
                &lt;extensions&gt;true&lt;/extensions&gt;<br />
                &lt;configuration&gt;<br />
                    &lt;archive&gt;<br />
                        &lt;manifestEntries&gt;<br />
                            &lt;HK2-Export-Package&gt;<br />
                                sahoo.hello.api<br />
                            &lt;/HK2-Export-Package&gt;<br />
                        &lt;/manifestEntries&gt;<br />
                    &lt;/archive&gt;<br />
                &lt;/configuration&gt;<br />
            &lt;/plugin&gt;<br />
        &lt;/plugins&gt;<br />
    &lt;/build&gt;<br />
</pre></p>

<p>The above syntax is same as what is applicable to <a href="http://maven.apache.org/plugins/maven-jar-plugin/">maven-jar-plugin</a>.</p>

<p><u><strong>Step 3: Define contract classes</strong></u> <a href="http://weblogs.java.net/blog/ss141213/examples/2nd-hello-world-hk2-sample/hello2-impl/Foo.java.txt">Foo.java</a> and <a href="http://weblogs.java.net/blog/ss141213/examples/2nd-hello-world-hk2-sample/hello2-impl/Bar.java.txt">Bar.java</a></p>

<p>In HK2, a contract is a Java interface which is annotated with <a href="https://hk2.dev.java.net/nonav/auto-depends/apidocs/org/jvnet/hk2/annotations/Contract.html">@Contract</a>. Typically a service or a component has two parts, viz: an interface class which defines the public interface of the service and an implementation class. HK2 allows you to develop a contract-less component as well. In HK2, the interface is annotated with @Contract, where as the implementation is annotated with <a href="https://hk2.dev.java.net/nonav/auto-depends/apidocs/org/jvnet/hk2/annotations/Service.html">@Service</a>.<br />
If you don't know why HK2 requires you to use @Contract, don't worry, it will be cleared in due course of time.<br />
In our case, both <a href="http://weblogs.java.net/blog/ss141213/examples/2nd-hello-world-hk2-sample/hello2-impl/Foo.java.txt">Foo.java</a><br />
Foo.java and <a href="http://weblogs.java.net/blog/ss141213/examples/2nd-hello-world-hk2-sample/hello2-impl/Bar.java.txt">Bar.java</a>  have such annotations in place. Keeping the true spirit of modularisation, we have defined Foo and Bar in sahoo.hello.api package, which is the package that is being exported by hello-impl module. The implementations are hidden from other modules. </p>

<p><u><strong>Step 4:Decide the scope of components</strong></u><br />
There is something called scope attribute in @Contract. The default value for scope is <a href="https://hk2.dev.java.net/nonav/auto-depends/apidocs/org/jvnet/hk2/component/Singleton.html">Singleton.class</a>. As the name suggests, when you ask the component manager for a component, it uses this information to decide whether to create a new instance or return an existing instance. If it decides to return an existing instance, the scope can further control where it searches for an existing instance. Singleton, as the name suggests, implies that there will be no more than one such instance of this contract type. There is another scope defined in HK2 called <a href="https://hk2.dev.java.net/nonav/auto-depends/apidocs/org/jvnet/hk2/component/PerLookup.html">PerLookup.class</a> which means every time you ask for such a component, a new instance is created by HK2 component manager as if you called the constructor. A very powerful feature of HK2 is the notion of <em>user defined scope</em>.  I have a sample ready that shows how to use your own scope, but let me defer discussion on that to another day. <br />
In our case, we are relying on the default scope.</p>

<p><u><strong>Step 5:Define component classes</strong></u> <a href="http://weblogs.java.net/blog/ss141213/examples/2nd-hello-world-hk2-sample/hello2-impl/FooImpl.java.txt">FooImpl.java</a> and <a href="http://weblogs.java.net/blog/ss141213/examples/2nd-hello-world-hk2-sample/hello2-impl/BarImpl.java.txt">BarImpl.java</a></p>

<p>They are both defined in a package called sahoo.hello.impl, which is not exported by our module. Now let's take a closer look at our component classes. <br />
A component class must be annotated with @Service.<br />
A component class must have public, no-arg constructor. <br />
A component can depend on other components. To express such dependency, a component can use @Inject annotation. While specifying @Inject, one should specify the contract interface type in order to avoid tight coupling with any given implementation if possible. Our component Foo.java follows all these rules as shown below:<br />
<pre><br />
@Service<br />
public class FooImpl implements Foo {<br />
    @Inject Bar bar;</p>

<p>    public FooImpl() {<br />
        System.out.println("FooImpl() called");<br />
    }</p>

<p>    public void doit() { bar.doit();}<br />
}<br />
</pre></p>

<p>A natural question is when does the injected field bar get initialized? It is initialized by HK2 framework after the constructor call, which means you should not be accessing this field in your default constructor. If you need to specify some business logic as part of construction, then make your component implement <strong>PostConstruct</strong> interface.</p>

<p><u><strong>Step 6: Write a startup module</strong></u><br />
So far, we have described about hello-impl module which defines two contracts called Foo and Bar, but how does HK2 know about it? Who uses them? That's where our startup module comes into picture. Remember, in my previous blog, I told this is the primordial module? This is the module that consumes those contracts. Now let's look at the only class that is defined in this module:<br />
<pre><br />
@Service<br />
public class MyStartup implements ModuleStartup<br />
{<br />
    @Inject Habitat habitat;<br />
    @Inject Foo foo;</p>

<p>    public void setStartupContext(StartupContext context) {<br />
    }</p>

<p>    public void run() {<br />
        System.out.println("Hello World - My first HK2 Sample");<br />
        System.out.println("Injected foo = " + foo);<br />
        Foo lookedUpFoo = habitat.getComponent(Foo.class, null);<br />
        System.out.println("habitat.getByComponent(Foo.class, null) = " +<br />
                           lookedUpFoo);<br />
        // Since Foo is Singleton scoped, the following assertion holds good<br />
        assert(foo == lookedUpFoo);<br />
        foo.doit();<br />
    }</p>

<p>}<br />
</pre></p>

<p>It is itself a component, for it is annotated with @Service. What contract does it have? It's ModuleStartup. Since it is a component, it can use dependency injection. See how it is injected with a Foo object and a Habitat object. What is this Habitat object? Well, Habitat is the component manager in HK2. </p>

<p>Since, hello-startup module uses interfaces from hello-impl module, we have to set appropriate dependency in hello-startup's pom.xml. When we do this, out hk2-maven-plugin is smart enough to generate the following manifest headers in hello-startup's META-INF/MANIFEST.MF:</p>

<p><em>HK2-Import-Bundles: sahoo:hello2-impl, com.sun.enterprise:hk2</em></p>

<p>That's it. You are all set to build and run the sample. </p>

<p><u><strong>Observations</u></strong><br />
You can see HK2 automatically starting hello2-impl module when it tries to start the primordial module. You can also see <em>instantiation cascading</em>: MyStartup -> Foo -> Bar because of Bar injected in Foo injected in MyStartup. Similarly, you can see Singleton scope in action. Next time, when the code asks for Foo type component to the component manager, it is returned the previous instance. To test package hiding, change the class to load FooImpl.class directly from MyStartup, and you will get a ClassNotFoundException.</p>

<p><strong>Q1. Why does HK2 use @Contract and @Service?</strong><br />
It's an ease of development thing. Even Java SE platform provides a <a href="http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html">service framework</a>, but that does not require any annotations, but why HK2 requires? Java SE requires programmers to generate META-INF/services file as described <a href="http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Service%20Provider">here</a>, where as HK2 generates the appropriate meta-information by parsing the annotations at compile time. This is done by HK2 supplied hk2:compile goal.</p>

<p><strong>Q2. What is Habitat in HK2?</strong><br />
This is the component manager in HK2. Think like JNDI Naming Manager in Java EE. Well, it's much more than that actually. More discussion on Habitat some other day. Got to sign off for the day.</p>

<p><u><strong>Conclusion</strong></u><br />
I hope you found this useful. As usual, your comments are useful. Stay tuned for more on <a href="http://technorati.com/tag/hk2" rel="tag">HK2</a> and <a href="http://technorati.com/tag/GlassFish" rel="tag">GlassFish</a>.</p>]]>

</content>
</entry>
<entry>
<title>Getting started with HK2 - Part I</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2008/01/getting_started.html" />
<modified>2008-01-28T14:30:19Z</modified>
<issued>2008-01-28T14:30:07Z</issued>
<id>tag:weblogs.java.net,2008:/blog/ss141213/298.9080</id>
<created>2008-01-28T14:30:07Z</created>
<summary type="text/plain">Using a &quot;Hello World&quot; type sample, I show how to get started with HK2. Those of you who don&apos;t know what is HK2, it is the short name for &quot;Hundred Kilobyte Kernel,&quot; HKK further reduced to HK2. It is being used in development of ultra light weight, modular, next generation GlassFish application server. HK2 is not just meant for GlassFish or application server type applications; any Java SE programmer can use it to write modular applications. It has a very nice component model with IoC support.</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p><a href="http://weblogs.java.net/blog/ss141213/examples/hello-world-hk2-sample.zip">Download The Sample</a></p>

<p>Now that I am working in <a href="http://hk2.dev.java.net">HK2</a>, I shall share my experiences of HK2 with others via my blogs. I firmly believe that examples are a great way to learn a new technology. So, I will start with a "Hello World" type application. The fact that you are reading this blog makes me think that you already know what HK2 is. Although HK2 is being used in development of ultra light-weight, modular, next generation GlassFish application server, any Java SE programmer can use it to write modular applications. It has a very nice component model with <a href="http://martinfowler.com/articles/injection.html">IoC</a> support. In fact, this sample has nothing to do with server side programing. The complete sample along with Maven build scripts, etc. can be downloaded from <a href="http://weblogs.java.net/blog/ss141213/examples/hello-world-hk2-sample.zip">here</a>.</p>

<p><u>Structure of the sample</u><br />
<pre><br />
hello-world-hk2-sample/<br />
                      /pom.xml<br />
                      /hello-startup/pom.xml<br />
                                    /src/main/java/sahoo/hello/startup/MyStartup.java<br />
</pre></p>

<p>As you notice, even though there is only one module, named hello-startup, I have decided to keep a top level pom.xml with packaging type <strong>pom</strong> and kept hello-startup module in a sub-project. I have done so because I know, in reality, one has multiple modules, so why not get used to that kind of structure from beginning?</p>

<p><u>Prerequisite:</u><br />
1. Maven 2<br />
2. Java SE 6 or above. <br />
You can use Java SE 5, but you need to get hold of a StAX implementation and put it in classpath, for HK2 needs StAX at runtime.</p>

<p><u>How to build</u><br />
<em>mvn -f hello-world-hk2-sample/pom.xml install</em></p>

<p>(-f option to mvn instructs it to use a specified pom.xml. It is equivalent to cd to hello-world-hk2-sample and invoking 'mvn install')</p>

<p><u> How to run</u><br />
There are a couple of options:<br />
1. Using maven:<br />
HK2 provides a plugin goal (hk2:run) which I find very handy to use. This goal must be invoked using the statup module's pom. So, you can invoke it like this:</p>

<p><em>mvn -f hello-world-hk2-sample/hello-startup/pom.xml hk2:run</em></p>

<p>2. Running a start up script:</p>

<p><em>./hello-world-hk2-sample/run.sh</em></p>

<p><a href="http://weblogs.java.net/blog/ss141213/examples/hello-world-hk2-sample/run.sh.txt">run.sh</a> is a very simple script that copies all the necessary HK2 jar files from your Maven local repository to a directory called ./lib. It also copies your application jar files to ./lib. Then it launches HK2 using the following command:</p>

<p><strong>java -jar ./lib/hk2-0.2-SNAPSHOT.jar</strong></p>

<p><strong>Note:</strong> There are a couple of variables like JAVA_HOME and MAVEN_REPO_LOCAL in run.sh that you need to configure for your environment.</p>

<p><u>Sample Description:</u><br />
Let's now take a look at our program. <br />
1. First the <a href="http://weblogs.java.net/blog/ss141213/examples/hello-world-hk2-sample/hello-startup/pom.xml.txt">pom.xml</a>:<br />
A. The packaging type is <strong>hk2-jar</strong>. Who provides this packaging support? HK2 provides a plugin called <strong>hk2-maven-plugin</strong> which provides this packaging support. It helps generating necessary manifest headers in our module jar. Since maven does not know about this plugin, we configure it in our build section. <br />
B. We also specify dependency on HK2 module in the dependency section so that we can use HK2 APIs in our program. Please note that I specify the HK2 version as a property which is set in the <a href="http://weblogs.java.net/blog/ss141213/examples/hello-world-hk2-sample/pom.xml.txt">parent pom.xml</a>. This allows me to control it in one place only. Rest of the pom.xml needs no explanation.</p>

<p>2. Let's now take a look at our only class, <a href="http://weblogs.java.net/blog/ss141213/examples/hello-world-hk2-sample/hello-startup/MyStartup.java.txt">MyStartup.java</a>.<br />
It is annotated as <a href="https://hk2.dev.java.net/nonav/auto-depends/apidocs/org/jvnet/hk2/annotations/Service.html">@Service</a> and implements <a href="https://hk2.dev.java.net/nonav/hk2/apidocs/com/sun/enterprise/module/bootstrap/ModuleStartup.html">ModuleStartup</a>. Both are needed because hello-startup is the <strong>primordial module</strong> - the first user supplied module to be started by HK2. When HK2 starts, it searches all the modules for a class that meets the above criteria. If it finds only one such class, then it considers the module containing the class as the main bundle. It then instantiates the class and calls the setStartupContext(). It then calls the run() method of the ModuleStartup interface. Our System.out.println code is part of the run().</p>

<p><u>Conclusion</u><br />
I know this sample does not show how HK2 manages module dependency, class loading, component injection, etc. Stay tuned, more blogs about <a href="http://technorati.com/tag/hk2" rel="tag">HK2</a> coming soon... As usual, comments are most welcome.</p>

<p><u>Useful Links:</u><br />
<a href="https://hk2.dev.java.net/develop.html">How to develop module in HK2</a><br />
More blogs about <a href="http://technorati.com/tag/GlassFish" rel="tag">GlassFish</a><br />
</p>]]>

</content>
</entry>
<entry>
<title>My experience while writing an annotation processor - part II</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2007/11/my_maven_experi.html" />
<modified>2007-11-30T09:39:38Z</modified>
<issued>2007-11-30T09:39:21Z</issued>
<id>tag:weblogs.java.net,2007:/blog/ss141213/298.8737</id>
<created>2007-11-30T09:39:21Z</created>
<summary type="text/plain">In my last blog I talked about Java related issues that I faced while writing an annotation processor that would generate persistence.xml file when I compile my JPA entity classes. To complete the story, this time I will share my maven experiences.</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>J2SE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p><a href="http://weblogs.java.net/blog/ss141213/archive/2007/11/my_experience_w.html">Earlier</a> I shared the Java/JDK issues that I faced while writing an <a href="http://weblogs.java.net/blog/ss141213/archive/2007/11/a_javac_plugin_1.html">annotation processor</a>. Today I am going to share my experience of using Maven. The issues have hardly anything to do with the annotation processor itself. If you are curious about what that annotation processor does, please refer to my earlier <a href="http://weblogs.java.net/blog/ss141213/archive/2007/11/a_javac_plugin_1.html">blog</a>. Now, without wasting much time, let me describe the issues in the order in which I encountered them.</p>

<p><u>1. Which maven-jaxb-plugin to use?</u><br />
Since my annotation processor reads and writes XML, I did not hesitate a moment to choose <a href="http://JAXB.dev.java.net">JAXB</a> as part of my solution. Next I had to search for a Maven plugin for XJC, the JAXB code generator. When I googled for Maven JAXB plugin, it came up with multiple answers. Need-less-to-say, it was confusing. Knowing <a href="http://weblogs.java.net/blog/kohsuke/">Kohsuke</a> and the popularity of <a href="http://JAXB.dev.java.net">JAXB java.net project</a>, I preferred <a href="https://jaxb.dev.java.net/jaxb-maven2-plugin/">their plugin</a> as opposed to the one available in <a href="http://repo1.maven.org/maven2/maven-plugins/maven-jaxb-plugin/">Maven repo</a>.</p>

<p><u>2. Not able to pass a URL to maven-jaxb-plugin</u><br />
Please refer to <a href="http://forums.java.net/jive/thread.jspa?messageID=246859">my posting in JAXB forum</a> where I have raised this issue. Lack of this facility forced to maintain a copy of the schema document in my source tree. I hate such duplication.</p>

<p><u>3. Not able to specify compiler configuration differently for different phases</u><br />
Obviously, my main source code tree (<em>src/main</em>) contains the annotation processor and other supporting code, and test source tree (<em>src/test</em>) is where I have the test cases to test the processor. I use auto-discovery of annotation processor by javac, which means if my processor is in javac's classpath, then javac invokes it automatically. Of course, I do <strong>not</strong> want my processor to be active when I am compiling the processor itself; I only want it to be used during test compilation. Since a previous successful compilation makes it available to javac to execute, I had to find a way to avoid annotation processing during main source code compilation. javac has an option <a href="<a href="http://java.sun.com/javase/6/docs/technotes/tools/solaris/javac.html#processing">-proc:none</a> that fits my requirement. All I had to do is to use that option during compilation, but not use it during <strong>testCompilation</strong> goal of the <a href="http://maven.apache.org/plugins/maven-compiler-plugin/">maven-compiler-plugin</a>. I was surprised to find that there is no straight forward way to configure maven-compiler-plugin differently for different phases. The compiler always has one configuration that it applies to all the phases. In addition to that, you can specify extra configurations that it applies when executing certain goal. My discussion in <a href="http://mail-archives.apache.org/mod_mbox/maven-users/200711.mbox/%3c4743CEB4.9000204@Sun.COM%3e">Maven User forum</a> has not made much progress, except that I found a work around to my problem. Eventually, I configured the plugin like this:<pre><br />
      &lt plugin&gt<br />
        &lt groupId&gt org.apache.maven.plugins&lt/groupId&gt<br />
        &lt artifactId&gt maven-compiler-plugin&lt/artifactId&gt<br />
        &lt configuration&gt<br />
          &lt compilerArgument&gt -proc:none&lt/compilerArgument&gt<br />
        &lt/configuration&gt<br />
        &lt executions&gt<br />
          &lt execution&gt<br />
            &lt id&gt run-annotation-processor-only&lt/id&gt<br />
            &lt phase&gt process-test-resources&lt/phase&gt<br />
            &lt goals&gt &lt goal&gt testCompile&lt/goal&gt &lt/goals&gt<br />
            &lt configuration&gt<br />
              &lt compilerArgument&gt -proc:only&lt /compilerArgument&gt<br />
            &lt/configuration&gt<br />
          &lt/execution&gt<br />
        &lt/executions&gt<br />
      &lt/plugin&gt </pre></p>

<p>If you carefully look at it, you can see that the above pom would invoke the compiler-plugin three times in the following order to execute test phase:<br />
1) compile goal - during compile phase, during which it uses -proc:none option.<br />
2) testCompile goal - during process-test-resources, during which it uses <a href="http://java.sun.com/javase/6/docs/technotes/tools/solaris/javac.html#processing">-proc:only</a> option.<br />
3) testCompile goal - during test-compile phase, during which it uses same configuration as compile goal.<br />
An excellent overview Maven's build life cycle and various phases that it comprises of is available <a href="http://www.sonatype.com/book/lifecycle.html#plugins_and_the_lifecyle">here</a>.</p>

<p><u>4. Not able to pass multiple compilerArguments to javac</u><br />
I have already <a href="http://www.nabble.com/Not-able-to-pass-multiple-arguments-to-javac-tf4857909s177.html">discussed</a> this in Maven forum and the outcome is <a href="http://jira.codehaus.org/browse/MCOMPILER-62"> enhancement request</a>.</p>

<p><u>5. Maven not printing information printed using Messager</u><br />
In my code, I use <a href="http://java.sun.com/javase/6/docs/api/javax/annotation/processing/Messager.html">Messager</a> object to report progress of my annotation processor. Those messages appear in my console when I run javac directly, but they appear nowhere when maven invokes the compiler using <a href="http://maven.apache.org/plugins/maven-compiler-plugin/">maven-compiler-plugin</a>. Finally, I switched to using System.out, not a bright idea as it defeats the purpose of a Messager in the first place. Debugging javac launched via Maven, I gather some more information and have sent a mail to Maven User forum. Let's see what they respond. Until then, I am afraid, one has to use System.out if they want their annotation processor output to be visible in console while using Maven.</p>

<p><u>Conclusion:</u><br />
Other than these issues, I had a <strong>pleasant</strong> experience of using Maven. I am not a maven expert - I am just starting. I have earlier used Maven (remember being a GlassFish developer, I execute maven scripts every day), but those were maven1 scripts that someone else has written, and I just run them. This was the first time I wrote maven2 scripts and used them. I do have a reasonable amount of experience of using build tools like Make, Ant, etc. Make is still my favorite tool - I used <a href="http://www.gnu.org/software/make/">GNU Make</a> quite a lot in the past when I used to work primarily in C++. I am particular interested in Maven because it addresses a key issue in software development - that of <strong>dependency management</strong>. It's a <em>bill of materials</em> issue in software well addressed by Maven. I don't think I need to praise Maven any more as lots of people have started to use it and we at <a href="http://GlassFish.dev.java.net">GlassFish</a> project have started using it in <a href="http://wiki.glassfish.java.net/Wiki.jsp?page=V3DevelopmentInstructions">very actively</a>. Here are a couple of thoughts:<br />
1. I think any new addition to the maven central repository needs to be carefully evaluated. It would be better to have a staging (or beta) repository where experimental stuff can go. Only when an artifact is popular or standardized, it should find its way to the central repository. I know there is a process in place, but I still think the repository has far too many stuff out there than what it should have at this point of time. </p>

<p>2. Having wrappers(plugins) for underlying tools has its merits and demerits. e.g. underlying XJC plugin allows me to pass a URL, where as the maven-jaxb-plugin does not. Would it be better to just let people invoke the underlying tool directly, just as they did in Make? Or is that out of fashion now? </p>

<p>I look forward to your comments. Thanks for reading.<br />
</p>]]>
<![CDATA[<p>More blogs about <a href="http://technorati.com/tag/maven2" rel="tag">Maven2</a>...</p>]]>
</content>
</entry>
<entry>
<title>My experience while writing an annotation processor - part I</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2007/11/my_experience_w.html" />
<modified>2007-11-27T17:40:27Z</modified>
<issued>2007-11-27T17:40:20Z</issued>
<id>tag:weblogs.java.net,2007:/blog/ss141213/298.8715</id>
<created>2007-11-27T17:40:20Z</created>
<summary type="text/plain">Recently I was writing an annotation processor that would generate persistence.xml file when I compile my JPA entity classes. While writing this compiler plugin certain things did not behave the way I was expecting. I will talk about them in two parts. In this part I will talk about Java related issues.</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>

<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p>Recently I was writing an <a href="http://weblogs.java.net/blog/ss141213/archive/2007/11/a_javac_plugin_1.html">annotation processor</a> that would generate a persistence.xml file when I compile my JPA entity classes. If you are a Java Persistence API user, then you may actually be interested in that annotation processor. OK, enough of shameless self promotion. Coming to the issue I want to discuss in this blog... While writing the annotation processor, certain things did not happen as per my expectation. I will <strong>share</strong> them with you so that you won't waste time as I did. All those issues are generic in nature.</p>

<p><u>1. Thread.getContextClassLoader is not the class loader you want to use</u><br />
In my annotation processor's process() method, I wanted to load a resource (say) foo/bar.xml which is part of the same jar which houses the annotation processor itself. So, I wrote:<br />
<code>Thread.currentThread().getContextClassLoader().getResourceAsStream("foo/bar.xml"). </code><br />
This returns null. So, I had to change my code to:<br />
<code>this.getClass().getClassLoader().getResourceAsStream("foo/bar.xml").</code><br />
May be it is by design, in that case I don't understand the rationale. Why the class loader of the thread executing my annotation processor is not able to load a resource which is part of a jar that is passed as -classpath to javac. More over, it's the same jar from where the annotation processor has been loaded!</p>

<p><u>2. Filer.getResource(SOURCE_PATH...) throws NPE if -sourcepath not specified</u><br />
In my annotation processor, I wanted to locate a file in <a href="http://java.sun.com/javase/6/docs/api/javax/tools/StandardLocation.html#SOURCE_PATH">source path</a>, so I wrote the following code:<br />
<code>FileObject fo = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "", "META-INF/persistence.xml"); </code><br />
It throws NullPointerException if I do <strong>not</strong> specify <em>-sourcepath</em> option while invoking javac. I have two questions:<br />
1) Is "." not the default value for source search path?<br />
2) Instead of throwing an IOException as per the <a href="http://java.sun.com/javase/6/docs/api/javax/annotation/processing/Filer.html#getResource(javax.tools.JavaFileManager.Location,%20java.lang.CharSequence,%20java.lang.CharSequence)">javadocs of getResource</a>, why is it throwing an NPE?<br />
The stack trace is available in the <a href="http://forums.java.net/jive/message.jspa?messageID=246717">unanswered forum posting</a> of mine.</p>

<p><u>3. Filer.createResource ignores directory part of relative URI</u><br />
My annotation processor tries to create an output file called META-INF/persistence.xml in the <a href="http://java.sun.com/javase/6/docs/api/javax/tools/StandardLocation.html#CLASS_OUTPUT">classes output directory (i.e. -d option to javac)</a>. So, I wrote following code:<br />
<code>final FileObject fo = processingEnv.getFiler().createResource(<br />
                    StandardLocation.CLASS_OUTPUT, // -d option to javac<br />
                    "",<br />
                    "META-INF/persistence.xml",<br />
                    null);</code><br />
This works as long as I pass -d option to javac. e.g., if I invoke:<br />
<em>javac -d . Foo.java</em><br />
it creates ./META-INF/persistence.xml. But, if I invoke<br />
<em>javac Foo.java</em><br />
it creates ./persistence.xml! Where is my META-INF directory gone?</p>

<p><u>4. javac does not print enough information about an exception</u><br />
I am very surprised to find that javac does not print the stack trace of exceptions that are thrown by annotation processors, not even in <strong>-verbose</strong> mode. Nor does it tell me which annotation processor threw the exception. Given below is an example of javac output in -verbose mode:<br />
<em>Round 1:<br />
input files: {sahoo.EmploymentRecord}<br />
annotations: [javax.persistence.Embeddable]<br />
last round: false<br />
error: Exception thrown while constructing Processor object: java.lang.NullPointerException</em><br />
My <a href="http://forums.java.net/jive/message.jspa?messageID=246718">question in the JDK forum</a> has fallen into deaf ears.<br />
Of course, the work around is a simple one - just catch all exceptions in your code and log them before re-throwing. But, I think I should not have to do this.</p>

<p><u>5. Not able to debug annotation processor</u><br />
It's my lack of knowledge. Until now, I never had to debug javac. Now that I am writing some code that gets called as part of javac, I felt the need to debug javac. I have still not found a way to do so. I tried passing the standard JVM debug options using "-J" option, but in vain. If you know how to attach a debugger to javac, please let me know. I use NetBeans IDE.</p>

<p><u>6. Maven not printing information printed using Messager</u><br />
This is more of an issue about how maven-javac-plugin interacts with javac. I am using Maven 2.0.7. In my code, I use <a href="http://java.sun.com/javase/6/docs/api/javax/annotation/processing/Messager.html">Messager</a> object to report progress of my annotation processor. Those messages appear in my console when I run javac directly, but they appear nowhere when maven invokes the compiler using <a href="http://maven.apache.org/plugins/maven-compiler-plugin/">maven-compiler-plugin</a>. Finally, I switched to using System.out, not a bright idea as it defeats the purpose of a Messager in the first place, but I just could not afford the extra time required to get to the root cause. </p>

<p>As usual, your comments are most welcome. Next time, I shall share the issues that I faced while using Maven. </p>]]>

</content>
</entry>
<entry>
<title>A javac plugin to manage your persistence.xml</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2007/11/a_javac_plugin_1.html" />
<modified>2007-11-26T15:54:52Z</modified>
<issued>2007-11-26T15:54:43Z</issued>
<id>tag:weblogs.java.net,2007:/blog/ss141213/298.8700</id>
<created>2007-11-26T15:54:43Z</created>
<summary type="text/plain">Java Persistence API specification requires its users to not only provide a persistence.xml file but also enumerate managed persistence class names in that file. In this article, I talk about a Java compiler plugin that can create the persistence.xml file for you automatically during normal course of Java code compilation and show how easy it is to use in your existing build scripts - be it maven or ant or shell script.</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>J2EE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p>I am glad to say that in most cases, I do <strong>not</strong> write a persistence.xml file any more. No, I am not using any IDE to generate it for me, nor has the spec relaxed any requirement. We will discuss some other time why persistence.xml is a necessary evil. Then what has changed? Well, my compiler creates it for me - yes, I said <strong>javac creates it for me</strong>. When I execute<br />
<em>javac -d . -classpath ... FooEntity.java BarEntity.java Main.java</em><br />
, a META-INF/persistence.xml file with necessary entries is created next to my .class file. See an <a href="http://weblogs.java.net/blog/ss141213/pxml-javac-plugin/persistence.xml.txt">example</a> <br />
of such a generated file. If there already exists a persistence.xml, then the above command just updates the managed persistence class names in it. It does not matter whether javac is invoked from command line, or Ant or <strong>Maven</strong>. To a certain extent, I can even control what goes into that file. e.g. I can choose the provider name, and it generates appropriate entries specific to the provider. Similarly I can also specify what should be the persistence-unit name and so on. Interested? You can use it. Read on...</p>

<p>No, I have <strong>not</strong> modified javac. Starting with Java SE 6, the <a href="http://java.sun.com/javase/6/docs/technotes/guides/javac/index.html"> Java Compiler</a>  allows users to plug in an <a href="http://java.sun.com/javase/6/docs/api/javax/annotation/processing/Processor.html">annotation processor</a> which gets called in an appropriate phase of compilation. If an annotation processor is available in javac's classpath, then javac can discover it using  <a href="http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Service%20Provider">service discovery mechanism</a>. Read <a href="http://java.sun.com/javase/6/docs/technotes/tools/solaris/javac.html#processing">Annotation Processing in javac</a> for further information. Using the said feature, I have written a simple, standard compliant javac plugin to provide the necessary functionality.</p>

<p><u>How you can use?</u><br />
You can <strong>download</strong> the plugin from <a href="http://weblogs.java.net/blog/ss141213/pxml-javac-plugin/pxml-javac-plugin-1.0-SNAPSHOT.jar">here</a><br />
; it is free, comes with no warranty. I will try to support it as time permits. <strong>To use it, just add thet jar file to classpath during compilation</strong>. That's it, now go onto compile your code as usual. Being a compiler plugin, it is not even required at runtime. Even if it's there in runtime classpath, it is harmless. So, the easiest option is to copy the jar to $JAVA_HOME/lib/ext. Since lib/ext is used in runtime as well, no matter how harmless the jar is, some people don't like this approach. More over, in a shared system, you may not even have permission to write to lib/ext. In such a case, you can follow one of the following options:</p>

<p>For command line javac invocation, just add it to compiler classpath using -classpath option. e.g.,<br />
<em>javac -classpath $HOME/pxml-javac-plugin.jar:$CLASSPATH *.java</em><br />
<strong>Ant</strong> users can modify the classpath attribute of the javac task. IDE users can add the plugin.jar in their project's compilation classpath.</p>

<p><u>Maven users:</u><br />
Step 1: Download the special maven2 repository format zip file from <a href="http://weblogs.java.net/blog/ss141213/pxml-javac-plugin/pxml-javac-plugin-maven.zip">here</a><br />
.<br />
Step 2: Install it in your local maven2 repository (by default ~/.m2/repository) by running following command:<br />
<em>unzip -d ~/.m2/repository pxml-javac-plugin-maven.zip</em><br />
Step 3: Modify your pom to add a compile time dependency to this plugin like this:<br />
<pre>&lt dependency&gt<br />
      &lt groupId&gt org.sanjeebsahoo&lt/groupId&gt<br />
      &lt artifactId&gt pxml-javac-plugin&lt/artifactId&gt<br />
      &lt version&gt 1.0-SNAPSHOT&lt/version&gt<br />
      &lt scope&gt compile&lt/scope&gt<br />
&lt/dependency&gt </pre><br />
That's it, no other change is needed. Isn't it straight forward to use?</p>

<p><u>How to pass additional options to the plugin:</u><br />
Sometimes you may like to pass additional options to our plugin to control what goes inside the persistence.xml. Currently supported options are described below. Unless specified, all options are optional. Since there can be multiple plugins for the javac, in order reduce probability of name collision, each option is prefixed with "pxmlplugin."<br />
1. <strong>pxmlplugin.provider</strong>: Acceptable values are toplink, hibernate, openjpa. Default value is toplink. Use this option when you don't have a persistence.xml file to start with and you want the provider to be other than toplink.<br />
2. <strong>pxmlplugin.pu</strong>: name of the persistence-unit. Default value is pu1. It solves two purpose, viz: <br />
a) when a new persistence.xml is created, this will be used as the name of the persistence-unit.<br />
b) when there already exists a persistence.xml with multiple persistence-units, this is used to select the desired one for update.<br />
3. <strong>pxmlplugin.verbose</strong>: prints additional information as debugging aid. By default, it is switched off.<br />
How you specify the option depends on which javac you are using. While using javac that comes with Sun JDK, prefix the option by <strong>-A</strong>. e.g.,<br />
<em>javac -Apxmlplugin.provider=hibernate -Apxmlplugin.pu=pu1 -Apxmlplugin.verbose -classpath pxml-javac-plugin-1.0-SNAPSHOT.jar Foo.java</em><br />
For non-Sun JDK, check your javac documentation.</p>

<p><u>Conclusion:</u><br />
I find this plugin very useful. It not only saves me from writing persistence.xml file in most of the case, it allows me to avoid duplicating class names in persistence.xml, thus saves me from troubles that can arise because of duplication of information. Would love to know your comments. Suggest improvements. I will be happy to make it when I get the time. Since the plugin uses all the standard APIs, I expect it to work with all Java SE 6 compatible javac. You can try and let me know. <br />
</p>]]>
<![CDATA[<p>References:<br />
<a href="http://java.sun.com/javase/6/docs/technotes/guides/apt/index.html">Annotation Processing Tool</a><br />
<a href="http://www.jcp.org/en/jsr/detail?id=269">JSR 269: Pluggable Annotation Processing API</a><br />
<a href="http://java.sun.com/javase/6/docs/technotes/tools/solaris/javac.html">Sun javac options</a><br />
<a href="http://maven.apache.org">Maven</a><br />
<a href="http://ant.apache.org/">Ant</a><br />
<a href="http://weblogs.java.net/blog/ss141213/archive/2005/12/how_to_automati.html">Earlier Work</a><br />
More blogs about <a href="http://technorati.com/tag/glassfish" rel="tag">glassfish</a> and <a href="http://technorati.com/tag/persistence" rel="tag">persistence</a><br />
</p>]]>
</content>
</entry>
<entry>
<title>Welcome to GlassFish @ FOSS.IN 2006</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2006/11/welcome_to_glas.html" />
<modified>2006-11-23T17:00:42Z</modified>
<issued>2006-11-23T17:00:29Z</issued>
<id>tag:weblogs.java.net,2006:/blog/ss141213/298.6026</id>
<created>2006-11-23T17:00:29Z</created>
<summary type="text/plain">FOSS.IN is one of the world&apos;s largest and most focussed FOSS events, held annually in India. GlassFish team of Sun Microsystems, which participate in one of the most important open source efforts initiated by Sun Microsystems, will not only talk about GlassFish &amp; Java EE platform, but will also have a live demo running at their booth. This blog gives details about the demo that&apos;s going to be shown their. </summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>J2EE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p><u>GlassFish at FOSS.IN 2006</u><br />
<a href="http://GlassFish.dev.java.net">GlassFish</a> team from <a href="http://www.sun.com">Sun Microsystems</a> will not only <a href="https://foss.in/2006/cfp/speakers/talkdetailspub.php?talkid=74">talk</a> about <strong>GlassFish & Java EE platform</strong> at the forth coming <a href="http://foss.in/2006/info/Main_Page">FOSS.IN 2006</a> event, but will also have a booth where they will answer questions about GlassFish and show case GlassFish technology that includes a <a href="http://weblogs.java.net/blog/ss141213/foss_2006_demo/GF_VisitorRegistration.htm">demo app</a> built using <a href="GlassFish.dev.java.net">GlassFish</a> and <a href="http://www.netbeans.org">NetBeans IDE</a>. The complete source code and build scripts for the demo app are available <a href="http://weblogs.java.net/blog/ss141213/foss_2006_demo/VisitorRegistration_src.zip">here</a>. Just unzip and explore. You can view the flash demo <a href="http://weblogs.java.net/blog/ss141213/foss_2006_demo/GF_VisitorRegistration.htm">here</a>. </p>

<p><u>Highlights of the demo:</u><br />
1. Learn to <em>develop</em> real world Java EE application.<br />
2. Learn to use Java EE 5 features of NetBeans like  <em>JPA entity bean wizard</em>, <em>Web Service wizard</em>,  <em>Web Service Client wizard</em>.<br />
3. <strong>Auto-completion</strong> of annotations, <strong>on-the-fly verification</strong> of code against Java EE spec, refactoring etc. features in NetBeans IDE<br />
4. Experience the <strong>integration</strong> of GlassFish with NetBeans<br />
5. Introduction to GlassFish web based <strong>administration</strong> interface<br />
6. Learn to use <strong>Verifier</strong> tool of GlassFish to check compliance against spec.</p>

<p><u>What does the demo app do?</u><br />
It's a Java EE application which will help us capturing details about visitors who visit us in FOSS.IN 2006. What is interesting about the demo app is that it is also used as a live application in our GlassFish booth area to capture details about visitors. It has:<br />
a) an <em>EJB</em> module containing a <strong>Web Service</strong> that stores visitor information in database using <a href="https://glassfish.dev.java.net/javaee5/persistence">Java Persistence API(EJB 3)</a>, also sends a follow up email to the visitor using <strong>JavaMail</strong>.<br />
b) a web module which contains a <strong>JSP</strong> which is used to capture visitor details. The JSP also acts as the web service client.</p>

<p><u>Important Links:</u><br />
<a href="http://weblogs.java.net/blog/ss141213/foss_2006_demo/GF_VisitorRegistration.htm">GlassFish flash demo</a><br />
<a href="http://weblogs.java.net/blog/ss141213/foss_2006_demo/VisitorRegistration_src.zip">Source code for the demo</a></p>

<p>See you in GlassFish presentation and booth at FOSS.IN.</p>

<p>More blogs about <a href="http://technorati.com/tag/GlassFish" rel="tag">GlassFish</a></p>]]>

</content>
</entry>
<entry>
<title>Persistence Context propagation</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2006/10/persistence_con.html" />
<modified>2006-10-27T19:01:58Z</modified>
<issued>2006-10-27T19:01:45Z</issued>
<id>tag:weblogs.java.net,2006:/blog/ss141213/298.5795</id>
<created>2006-10-27T19:01:45Z</created>
<summary type="text/plain">While using Java Persistence API in an enterprise application, there is often a need to access access entities in the same persistence context in different components involved in a particular request. Using a very simple Java EE application, this article shows how to achieve this in an elegant and portable way. The technique described here is completely portable across any Java EE 5 compatible application server because it uses a standard feature called *persistence context propagation*.</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>J2EE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p><u>What is persistence context propagation?</u><br />
A <strong>persistence context</strong>(PC) is a set of managed entity instances in which for any persistent entity identity there is a unique entity instance (this definition is taken from <a href="http://jcp.org/en/jsr/detail?id=220">Java Persistence API</a> spec, section 5.1). An <strong>Entity Manager</strong>(EM) provides the necesarry APIs to interact with a persistence context. <br />
There is often a need to access the entities in the <b>same</b> PC in different components (say multiple EJBs or web component and EJB etc.) involved in processing of a request. One way of doing this is to pass an EM instance around in the call stack from one component to another, but that's not so elegant as it pollutes the interfaces. A better and recommended approach is to use a feature called <strong>Persistence Context Propagation</strong> that is offered by the Java EE container. PC propagation allows multiple components of a Java EE application to share the same persistence context. Each component use their own EM which they obtain using dependency injection or JNDI lookup and when they use the EM in the contex of the same JTA transaction, container automaticaly binds the EM to the same PC. Thus application does not have to explicitly pass an EM from one component to another. This technique is <b>portable</b> across any Java EE 5 compatible application server.</p>

<p><u>Rules governing PC propagation</u><br />
1. Only a PC associated with a <strong>container managed EM</strong> can be propagated. </p>

<p>2. A PC is propagated <strong>along</strong> with the JTA transaction.</p>

<p>3. PC propagation is applicable only to <strong>local</strong> environments(i.e. one JVM). PC is not propagated across remote tiers even if the remote component is collocated in the same address space as the client.</p>

<p>4. A PC is propagated when the called component uses EM that belongs to the <strong>same  Entity Manager Factory</strong> as the caller. </p>

<p>5. It is an application error to attempt to propagate a PC to a SFSB that is already associated with a different PC. In such a case, EJB container throws EJBException to the caller. </p>

<p>Let's apply the rules (rule shown in ()) and see some cases where PC propagation takes place:</p>

<p>1. (rule #1) Since a container managed EM can only be obatined via <strong>@PersistenceContext</strong> or <strong>persistence-context-ref</strong>, PC propagation does not take place for EMs obtained using EntityManagerFactory.createEntityManager(). </p>

<p>2. (rule #2) A PC won't be propagated (e.g.) when an EJB with <strong>bean managed transaction</strong> or an EJB method with transaction attribute <strong>REQUIRES_NEW</strong>, <strong>NOT_SUPPORTED</strong> or <strong>NEVER</strong> is called because transactions are not propagated to such methods(see Chapter #13 of EJB 3.0 Core specification). More over, unless the caller is associated with a transaction, PC propagation will not happen. I don't know the behavior when a request is dispatched from one web component to another using using <strong>RequstDispatcher</strong> object. There are two questions that determine the answer, viz: a) is that ever considered a local call? b) does  web container propagates the JTA transaction along with the request? If you know the answer, let me know. Else, I will try to find out myself. </p>

<p>3. (rule #3) Don't expect PC to be propagated when you call a remote EJB even when the remote EJB happens to be running in the same JVM or part of the same application.</p>

<p>4. (rule #4) All the components that want to share the PC must use the same persistence unit. Container internally creates an EntityManagerFactory corresponding to a persistence unit and uses it to create EMs. <em>Persistence units defined in separate persistence.xml files or persistence units defined separately in one persistence.xml file are considered different no matter how idenically they are set up.</em> So, if components from two different modules in an EAR file (e.g. a Servlet calling an EJB) want to share PC, then the persistence unit must be packaged as an <strong>EAR scoped</strong> persistence unit (e.g. in a jar file in <strong>lib</strong> folder of the EAR).</p>

<p>5. (rule #5) If a component is associated with a PC then it can't call a local SFSB with a different extended PC to which current transaction context will be propagated. <strong>GlassFish</strong> reports this very nice message when I tried doing this in a test case: <em>javax.ejb.EJBException: There is an active transactional persistence context for the same EntityManagerFactory as the current stateful session bean's extended persistence context.</em> (rule #5)</p>

<p>These rules are not complete. Please refer to the JPA spec for more details.<br />
 <br />
<u>Sample Application</u><br />
Let's now use this feature in a simple Java EE application. In this example, a PC is shared between ReportServlet and UserCredentialManagerBean. I must say this is a bad example of PC propagation, but I just could not think of a better example for this article. The source code and build script can be downloaded from <a href="http://weblogs.java.net/blog/ss141213/examples/pc_propagation.zip">here</a>. Instructions to build and run are available in the <a href="http://weblogs.java.net/blog/ss141213/examples/pc_propagation/README">README</a>. There are lots of System.out.println statements in the code that gives an insight into what is happening. All those messages go to the <em>$GLASSFISH_HOME/domains/domain1/logs/server.log</em> by default. Although I am using <a href="http://GlassFish.dev.java.net">GlassFish</a> which is the <b>reference implementation</b> of Java EE 5 platform, you can use it in any Java EE 5 compatible application server. <br />
Let's now look at the relevant sample code:</p>

<p>1. <a href="http://weblogs.java.net/blog/ss141213/pc_propagation/web-app2/src/example/web/ReportServlet.java">ReportServlet.java</a><br />
:<br />
Since <a href="http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html">a servlet should not be injected with a PC</a>, ReportServlet gets hold of a container managed EM by looking up JNDI environment as shown below:<br />
<pre><br />
        EntityManager em = (EntityManager) new InitialContext().lookup(<br />
                    "java:comp/env/persistence/EM1");<br />
</pre><br />
The above look up returns a valid EM because the Servlet has declared a dependency on a PC for the persistence unit named <em>pu1</em> and has given this dependency a name <em>persistence/EM1</em> using the following code:<br />
<pre><br />
@PersistenceContext(name="persistence/EM1", unitName="pu1")<br />
public class ReportServlet extends HttpServlet {<br />
</pre><br />
ReportServlet <strong>begins</strong> a transaction using the injected <strong>UserTransaction</strong> object, obtains a <strong>managed</strong> entity instance by invoking lookup method of injected UserCredentialManager session bean, accesses the <strong>lazily</strong> fetched field of the entity and then commits the transaction in the code below:<br />
<pre><br />
        utx.begin();<br />
        UserCredential user = ucm.lookupUser(name);<br />
        for(LoginAttempt attempt : user.getLoginAttempts()) {...}<br />
        utx.commit();<br />
</pre></p>

<p>2. <a href="http://weblogs.java.net/blog/ss141213/pc_propagation/ejbs/src/example/ejb/impl/UserCredentialManagerBean.java">UserCredentialManagerBean.java</a>:<br />
This is a stateless session bean with <strong>container managed transaction</strong>(this is the default). It has a local business interface called UserCredentialManager. It uses an injected EM. The transaction attribute for lookup method is <strong>REQUIRED</strong> (default). </p>

<p>3. <a href="http://weblogs.java.net/blog/ss141213/pc_propagation/entities/persistence.xml">Persistence Unit</a>:<br />
There is an <strong>EAR scoped</strong> persistence unit called <strong>pu1</strong> which is defined in <strong>lib/entities.jar</strong>. Both the servlet and the session bean reference this persistence unit. There are two entity beans, viz <a href="http://weblogs.java.net/blog/ss141213/pc_propagation/entities/src/example/entity/UserCredential.java">UserCredential.java</a> and <a href="http://weblogs.java.net/blog/ss141213/pc_propagation/entities/src/example/entity/LoginAttempt.java">LoginAttempt.java</a></p>

<p>You may have noticed that ReportServlet does not use the EM in any meaningful way. So, it can be totally removed from ReportServlet and yet ReportServlet will be able to use the entity in the same PC as that of the EJB.</p>

<p>Let's see what would have happened if ReportServlet does not start the transaction before calling lookup method. Lookup method starts a new transaction and EJB container creates a new PC when the injected EM is used. This PC gets closed automatically when the transaction is ended at the end of that method, thus the returned  entity becomes <strong>detached</strong>. Since fetch type for loginAttempts is LAZY (by default it is lazy for collection valued fields) and the field has not been accessed by lookup method, accessing it in the Servlet is asking for trouble (see section #3.2.4 of the JPA spec). GlassFish persistence provider is generous enough to allow such an access, but when I tested using OpenJPA, it threw a NullPointerException.</p>

<p><u>Conclusion</u><br />
Hope you find this useful.</p>

<p><u>Resources</u><br />
<a href="http://weblogs.java.net/blog/ss141213/archive/2005/12/using_java_pers.html">Packaging of Java EE application that uses JPA</a><br />
<a href="http://weblogs.java.net/blog/ss141213/archive/2006/07/using_openjpa_a.html">Plugging in a thirdparty provider in GlassFish</a><br />
More blogs about <a href="http://technorati.com/tag/glassfish" rel="tag">glassfish</a> <a href="http://technorati.com/tag/persistence" rel="tag">persistence</a></p>]]>

</content>
</entry>
<entry>
<title>Using OpenJPA as Java Persistence API provider in GlassFish</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2006/07/using_openjpa_a_1.html" />
<modified>2008-05-12T19:23:19Z</modified>
<issued>2006-07-27T23:31:02Z</issued>
<id>tag:weblogs.java.net,2006:/blog/ss141213/298.5262</id>
<created>2006-07-27T23:31:02Z</created>
<summary type="text/plain">Pluggability of third party Java Persistence API providers into a Java EE container offers Java EE users exciting combinations to use. Earlier we had shown how to use Hibernate and Kodo in GlassFish. Now it&apos;s time for OpenJPA. I thought I shall give a try using it in GlassFish. This blog reinforces the fact that it could not be easier to plug in a third-party persistence provider in GlassFish.</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>J2EE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p>As this <a href="http://www.theserverside.com/news/thread.tss?thread_id=41489">theserverside.com announcement</a> shows, although <a href="http://incubator.apache.org/openjpa/index.html">OpenJPA</a> is still in the Apache incubator and not yet certified as a Java Persistence API compliant  provider, it is not far from that stage. There is a source download available and I must say, it is quite <strong>easy</strong> to build. If you want to use it in <a href="http://glassfish.dev.java.net">GlassFish</a>, then it's even <strong>easier</strong>. It is as simple as these intuitive steps:</p>

<p><br />
<u>Step #1: </u><a href="https://glassfish.dev.java.net/public/downloadsindex.html">Download and install GlassFish</a><br />
Download any of the latest builds of GlassFish v2 or v1_ur1 from <a href="https://glassfish.dev.java.net/public/downloadsindex.html#Promoted_binary_builds">here</a>. Install it in any directory of your choice. I refer to that as GLASSFISH_HOME.</p>

<p><br />
<u> Step #2: Build & Install OpenJPA</u><br />
Build OpenJPA using <a href="http://wiki.apache.org/incubator/openjpa/Building">these instructions</a>. It's really simple to build. The build process produces a zip file called <em>openjpa-project/target/filtered-site/resources/downloads/openjpa-0.9.0.zip</em><br />
Unzip this to any location. In this blog, I refer to that location as OPENJPA_HOME.</p>

<p><br />
<u>Step #3: Install OpenJPA in GlassFish</u><br />
All you need to do is to make OpenJPA implementation jar files available to GlassFish runtime. This can be achieved as follows:<br />
<pre> cp ${OPENJPA_HOME}/openjpa*.jar ${OPENJPA_HOME}/lib/*.jar ${GLASSFISH_HOME}/domains/domain1/lib </pre><br />
GlassFish will automatically make this jar part of its classpath next time when you <strong>restart</strong> the server.</p>

<p><br />
<u>Step #4: Edit persistence.xml</u><br />
Make a one line change to your persistence.xml to instruct GlassFish that we want to use OpenJPA as the persistence provider for this application. This is achieved by setting <provider> element to <strong>org.apache.openjpa.persistence.PersistenceProviderImpl</strong>. Shown below is a sample persistence.xml:<br />
<pre><br />
&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"&gt;<br />
    &lt;persistence-unit name ="em1"&gt;<br />
        &lt;provider&gt;org.apache.openjpa.persistence.PersistenceProviderImpl&lt;/provider&gt;<br />
        &lt;properties&gt;<br />
    &lt;/persistence-unit&gt;<br />
&lt;/persistence&gt;</pre></p>

<p><u>Step #5: Build and deploy your app</u><br />
Now you can build your Java EE application and deploy it to GlassFish.</p>

<p><br />
<u>Conclusion:</u><br />
As you can see, it is fairly simple to use any third-party provider in GlassFish. We had earlier talked about using <a href="http://weblogs.java.net/blog/ss141213/archive/2006/05/using_kodo_as_j.html">Kodo</a> and <a href="http://blogs.sun.com/roller/page/theaquarium?entry=running_hibernate_in_glassfish">Hibernate</a> in GlassFish. Please let us know, if you want any particular provider to be used in GlassFish that's not covered yet.</p>

<p><br />
<u>Resources</u><br />
If you want some working applications, then you can download them from my earlier blogs:<br />
a) <a href="http://weblogs.java.net/blog/ss141213/archive/2005/12/introduction_to.html">a web application that uses Java Persistence API</a> -- download the complete sample from <a href="http://weblogs.java.net/blog/ss141213/examples/blog1.zip">here</a><br />
b) <a href="http://weblogs.java.net/blog/ss141213/archive/2005/12/using_java_pers.html">a multi-tier Java EE application (web->ejb->JPA)</a> -- download the complete sample from <a href="http://weblogs.java.net/blog/ss141213/examples/blog5.zip">here</a>.<br />
After downloading, you need to change persistence.xml as described above. Then you can use the existing build.xml to build the app.</p>

<p><br />
<u>You don't have to read this if you followed the above instructions:</u><br />
I will share a problem that I ran into. I did some static analysis of the OpenJPA provider class using a little static analyser tool and figured out a list of dependent jar files. First time when I tried OpenJPA in GlassFish, I only copied the list of jars that I inferred from the static analysis phase. But I never realized that OpenJPA loads a lots of classes using reflection. I never imagined that not having a dependent jar file in CLASSPATH could lead to an exception like <br />
<em>org.apache.openjpa.persistence.ArgumentException: No table was given for persistent type example.UserCredential</em> even when table for that entity existed in database. Thanks to <a href="http://dev2dev.bea.com/blog/pinaki.poddar/">Pinaki</a> who pointed out that OpenJPA uses <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Service%20Provider"> Jar Service Provider</a> mechanism quite a lot so that its Kernel can be configured for either JPA or JDO environment. As a result of this, unless all the services are available in CLASSPATH, the kerner can't be correctly configured and that unfortnately leads to very weired exceptions. When I copied all the jar files from $OPENJPA_HOME/lib to $GLASSFISH_HOME/domains/domain1/lib, it worked. </p>

<p>Having said that, you actually <strong>don't</strong> need to copy the following jar files as GlassFish runtime already have those classes:<br />
geronimo-j2ee-connector_1.5_spec-1.0.1.jar<br />
geronimo-jms_1.1_spec-1.0.1.jar<br />
geronimo-jta_1.0.1B_spec-1.0.1.jar<br />
persistence-api-1.0.jar<br />
derby-10.1.3.1.jar<br />
It's no harm done even if you copy these jar files because GlassFish will simply ignore them.</p>

<p>Hope you find this blog useful. More blogs about <a href="http://technorati.com/tag/glassfish" rel="tag">glassfish</a> <a href="http://technorati.com/tag/persistence" rel="tag">persistence</a></p>

<p>Thanks.</p>]]>

</content>
</entry>
<entry>
<title>Using Kodo as Java Persistence API provider in GlassFish</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2006/05/using_kodo_as_j.html" />
<modified>2006-06-09T00:45:50Z</modified>
<issued>2006-05-28T11:44:45Z</issued>
<id>tag:weblogs.java.net,2006:/blog/ss141213/298.4914</id>
<created>2006-05-28T11:44:45Z</created>
<summary type="text/plain">Pluggability of third party Java Persistence API providers into a Java EE container offers Java EE users exciting combinations to use. Earlier we had shown how to use Hibernate in GlassFish. Now it&apos;s time for Kodo, which is another high performance &amp; popular O/R mapping solution. Recently Kodo 4.0GA was released and it supports Java Persistence API. So, I thought I shall give a try using it in GlassFish.</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>J2EE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p>Earlier we had shown how to <a href="http://blogs.sun.com/roller/page/theaquarium?entry=running_hibernate_in_glassfish">plug in Hibernate in GlassFish</a>. Now it's time for <strong>Kodo</strong>, which is another high performance & popular O/R mapping solution. Recently <a href="http://commerce.bea.com/showproduct.jsp?family=KODO&major=4.0&minor=0">Kodo 4.0GA</a> was released and it supports Java Persistence API 1.0. So, I thought I shall give a try using it in <a href="http://glassfish.dev.java.net">GlassFish</a>. The instructions are really simple. They do not involve any unreasonable steps. </p>

<p><u>Step #1: </u><a href="https://glassfish.dev.java.net/public/downloadsindex.html">Download and install GlassFish</a><br />
Install it in any directory of your choice. I refer to that location as GLASSFISH_HOME here. More details about which build of GlassFish to use is given towards the end of this blog.</p>

<p><u> Step #2:</u> <a href="http://commerce.bea.com/showproduct.jsp?family=KODO&major=4.0&minor=0">Download and install Kodo 4.0GA</a><br />
Yes, you should use Kodo 4.0GA or above. Don't use any of the earlier releases (like) 4.0RC1, RC2 etc. as there are issues that have been addressed in 4.0GA. Install Kodo in any directory of your choice. I refer to that location as KODO_HOME here.</p>

<p><u>Step #3: Install Kodo in GlassFish</u><br />
I particularly liked the fact that, kodo.jar is a self contained jar file. It does not depend on any other APIs except standard Java EE 5 APIs which are anyway available in GlassFish. So, all we need to do is to make kodo.jar available in GlassFish domain where we want to deploy the application. This can be achieved as follows:<br />
<pre> cp $KODO_HOME/lib/kodo.jar $GLASSFISH_HOME/domains/domain1/lib/ </pre><br />
GlassFish will automatically make this jar part of its classpath next time when you <strong>restart</strong> the server.</p>

<p><u>Step #4: Edit persistence.xml</u><br />
Make a couple of changes to your persistence.xml. First of all, we need to instruct GlassFish that we want to use Kodo as the persistence provider for this application. This is achieved by setting <provider> element to <strong>kodo.persistence.PersistenceProviderImpl</strong>. Secondly, we need to provide a valid Kodo license key. This is achieved by setting kodo.LicenseKey. Shown below is a sample persistence.xml:<br />
<pre><br />
&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"&gt;<br />
    &lt;persistence-unit name ="em1"&gt;<br />
        &lt;provider&gt;kodo.persistence.PersistenceProviderImpl&lt;/provider&gt;<br />
        &lt;properties&gt;<br />
            &lt;property name="kodo.LicenseKey" value="USE YOUR LICENSE KEY"/&gt;<br />
        &lt;/properties&gt;<br />
    &lt;/persistence-unit&gt;<br />
&lt;/persistence&gt;</pre></p>

<p><u>Step #5: Build and deploy your app</u><br />
Now you can build your Java EE application and deploy it to GlassFish.<br />
If you want some working applications, then you can download them from my earlier blogs:<br />
a) <a href="http://weblogs.java.net/blog/ss141213/archive/2005/12/introduction_to.html">a web application that uses Java Persistence API</a> -- download the complete sample from <a href="http://weblogs.java.net/blog/ss141213/examples/blog1.zip">here</a><br />
b) <a href="http://weblogs.java.net/blog/ss141213/archive/2005/12/using_java_pers.html">a multi-tier Java EE application (web->ejb->JPA)</a> -- download the complete sample from <a href="http://weblogs.java.net/blog/ss141213/examples/blog5.zip">here</a>.<br />
After downloading, you need to change persistence.xml as described above. Then you can use the existing build.xml to build the app.</p>

<p><u>Points to note:</u><br />
1. The choice of persistence provider is a runtime configuration. Development process, environment, source code and build scripts do not depend on the persistence provider. This is evident from the fact that the above examples were written originally for GlassFish and its default provider. We could use it for GlassFish/Kodo combination by just changing persistence.xml.</p>

<p>2. We can use <a href="http://blogs.sun.com/roller/page/java2dbInGlassFish">Java2DB</a> feature of GlassFish even while using Kodo. In fact, example #2 uses this. This feature is very handy for folks who don't have a prexisting database schema to work with.</p>

<p><u>Which GlassFish build to use?</u><br />
Use latest builds of GlassFish v2. If you want to use GlassFish v1, then you should read the following section as it discusses the two bugs that I discovered while using Kodo in GlassFish v1 (i.e.) SJSAS 9.0pe:</p>

<p><a href="https://glassfish.dev.java.net/issues/show_bug.cgi?id=679"> bug #679</a>: This affects web applications using Java Persistence API. <em>As a work around, you have to package <strong>enhanced classes</strong> in your web application</em>. Kodo comes with a program called <strong>kodoc</strong> which you can use to enhance the classes. I have already <strong>fixed</strong> this bug in GlassFish v2 and it will be available in GlassFish v2 build #04. Until build #04 is available, you can download the latest GlassFish v2 nightly build and use.</p>

<p><a href="https://glassfish.dev.java.net/issues/show_bug.cgi?id=223"> bug #233</a>: It affects EJBs using Java Persistence API. <em>As a work around, you have to redeploy the application every time you start the server</em>. I have a fix available in my local workspace which I am going to integrate very soon in GlassFish v2 (most likely, it shall be part of v2 build #04).</p>

<p><u>Conclusion:</u><br />
Pluggability of third party Java Persistence API providers into a Java EE container offers Java EE users exciting combinations to choose from and that too without sacrificing portability of their applications. Let us know if you are interested in any other provider to be used in GlassFish and we shall give it a try.<br />
More blogs about <a href="http://technorati.com/tag/glassfish" rel="tag">glassfish</a> <a href="http://technorati.com/tag/persistence" rel="tag">persistence</a></p>]]>

</content>
</entry>
<entry>
<title>Which GlassFish build to use?</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2006/05/which_glassfish.html" />
<modified>2006-06-09T00:45:50Z</modified>
<issued>2006-05-05T09:45:53Z</issued>
<id>tag:weblogs.java.net,2006:/blog/ss141213/298.4659</id>
<created>2006-05-05T09:45:53Z</created>
<summary type="text/plain">Some of the recent postings in the GlassFish forum suggest that there is some confusion in the GlassFish user community about which GlassFish build to use. This is largely because of activities happening in more than one branch in CVS. I will try to respond to the confusion here.</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>J2EE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p>Looking at some of the recent postings in <a href="http://forums.java.net/jive/forum.jspa?forumID=56&start=0">the GlassFish forum</a>, there appears to be some <a href="http://forums.java.net/jive/thread.jspa?threadID=14649&messageID=110753#110753">confusion</a> in the <a href="http://glassfish.dev.java.net">GlassFish</a> user community about which build to use. I will try to address the issue in this blog.</p>

<p>The main reason for this confusion is due to presence of two very active branches in the <a href="https://glassfish.dev.java.net/source/browse/glassfish">GlassFish CVS repository</a>, viz: <strong>SJSAS90_FCS_BRANCH</strong> and <strong>the trunk</strong> (a.k.a. the main branch). They look something like this:<br />
<pre><br />
                         <br />
                                   b48<br />
                                  /<br />
                                 b47<br />
                                /<br />
                               b46<br />
                              /<br />
                             b45<br />
                            /<br />
                           b44<br />
                          /<br />
                         b43<br />
                        /<br />
                       /SJSAS_90FCS_BRANCH<br />
                      /<br />
                     /             <br />
TRUNK__..._b41_b42__/____________________ TRUNK<br />
                    ^<br />
                    |<br />
               30 Mar 2006<br />
(The numbers starting with <strong>b</strong> are build numbers)<br />
</pre></p>

<p>As the name suggests, SJSAS90_FCS_BRANCH is used for release of <strong>Sun Java System/Application Server PE 9.0</strong> as well as <strong>Java EE 5 SDK</strong>. As the diagram shows, this branch was forked from the trunk around 30 March 2006. It is a highly controlled branch as it is used to release a product and currently this branch is in <strong>high resistance mode</strong> as the final release date is fast approaching. As a standard product release process, not all kinds of bug fixes are going into this branch. </p>

<p>The situation is very different for the trunk. It is open for checkins. In fact a lot of bug fixes and quite a few enhancements have gone into the trunk since SJSAS_90FCS_BRANCH was forked. If I have to single out any one module which has changed most in the trunk since the 9.0 branch was forked, then it will be <a href="https://glassfish.dev.java.net/javaee5/persistence/">entity-persistence</a> module, which is the Java Persistence API implementation module in GlassFish. Not all these fixes were back ported to the SJSAS_90FCS_BRANCH for obvious reasons. Be rest assured, a number of these bugs will eventually be made available in a subsequent <strong>Update Release(UR)</strong> for 9.0.</p>

<p><u>Difference between promoted builds and nightly build</u><br />
As the name suggests, <strong>nightly</strong> build happens every night. Before a binary is posted in the <a href="http://download.java.net/javaee5/installer-nightly/">nightly download site</a>, it must pass a predefined set of test cases. So, you can use a nightly build during development phase of your project. Typically after a series of nightly builds, one of the nihgtly builds get promoted and is made available in the <a href="https://glassfish.dev.java.net/public/downloadsindex.html#Promoted_binary_builds"> promoted builds' web site</a>. The typical frequency has been 1 week in GlassFish project. This allows the delta between two promotions to be significant. The number of tests that are run before promoting a nightly build is <strong>much larger</strong> than what are run to test the nightly builds.</p>

<p><u>Build Numbers/Name:</u><br />
Each promoted build has a unique name. e.g. b01, b02...,b48 are all names of promoted builds happening on different dates. The nightly builds also have a name. It has two components viz: the next promoted build number and the date on which it was built. e.g. glassfish-installer-b43-nightly-01_may_2006.jar.</p>

<p><u>What is the </u> <a href="http://forums.java.net/jive/thread.jspa?threadID=14649&messageID=110753#110753">confusion?</a><br />
If you look at the branch diagram, you shall see that the b41, b42 etc. were built using source from the trunk. After the FCS branch was forked, promoted builds like b43, b44, ..., b48 (this is the latest promoted build as I am writing this blog) were done using source code taken from SJSAS_90FCS_BRANCH. This has <strong>confused</strong> many users. When users see some bug being marked as fixed, it is natural for them to expect the fix to be available in the next promoted build, but that did not happen after b42. I feel it would have been better to call 9.0 branch builds as something like b43_90 and continue to use b43, b44 as build numbers for trunk builds. <br />
To specifically address such confusion, <a href="https://glassfish.dev.java.net/servlets/ProjectIssues">IssueTracker</a> has a field called <strong>target milestone</strong>, but <strong>at this point</strong>, it is not clear what should be used in this field when a fix is integrated into the trunk. I wish, we could just use 9.1. </p>

<p>Finally, there is no promoted builds happening on the trunk right now. If you look at the <a href="https://glassfish.dev.java.net/public/downloadsindex.html#Promoted_binary_builds">GlassFish promited builds download site</a>, you can see that after b42, there are no promotions happening on the trunk. Only nightly builds are happening as <a href="http://download.java.net/javaee5/installer-nightly/">GlassFish nightly build download site</a> shows. If you choose the platform of your choice there, you can see that there are download bundles are available with names like glassfish-installer-b43-nightly-01_may_2006.jar. Look at the date encoded in the  name. That conveys the date on which that binary was built. </p>

<p><u>When is situation going to improve?</u><br />
Recently a <a href="https://glassfish.dev.java.net/issues/show_bug.cgi?id=640">P1 issue (#640)</a> has been filed and very soon I am hoping to see promoted builds happening on trunk. </p>

<p><u>Conclusion</u><br />
In the mean while, if you are waiting for a build which fixes one of the bugs you are encountering, then you may use the latest nightly build. Use the date to decide which one is the latest build, don't assume that since the name contains b43, it is an old build.</p>]]>
<![CDATA[<p>More blogs about <a href="http://technorati.com/tag/glassfish" rel="tag">glassfish</a> <a href="http://technorati.com/tags/glassfish" rel="tag">glassfish</a></p>]]>
</content>
</entry>
<entry>
<title>Using Java Persistence API in application client in Java EE platform</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2006/03/using_java_pers_1.html" />
<modified>2006-06-09T00:45:50Z</modified>
<issued>2006-03-21T09:03:23Z</issued>
<id>tag:weblogs.java.net,2006:/blog/ss141213/298.4358</id>
<created>2006-03-21T09:03:23Z</created>
<summary type="text/plain">The Java Persistence API is the standard API for the management of persistence and object/relational mapping in Java EE 5 platform. It can be used in three types of containers, viz: ejb container, web container and application client container. In this blog, we will talk about using this API in application clients. We also discuss two different way of packaging the application.</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>J2EE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p>In <a href="http://java.sun.com/javaee/">Java EE 5</a> platform <a href="http://jcp.org/en/jsr/detail?id=220">Java Persistence API</a> can be used in three types of containers, viz: ejb, web and application client container. In my earlier blogs, I had talked about using this API in <a href="http://weblogs.java.net/blog/ss141213/archive/2005/12/introduction_to.html">web applications</a> and in <a href="http://weblogs.java.net/blog/ss141213/archive/2005/12/using_java_pers.html"> EJB applications</a>. This time we will talk about using Java Persistence API in application clients. We also discuss about two different way of packaging the application. You can download the <a href="http://weblogs.java.net/blog/ss141213/examples/jpa_acc.zip">complete sample</a>, unzip and run 'ant deploy' to see the sample in action. The steps are very simple as discussed below:</p>

<p><u>Step #1: Write entity bean</u> <a href="http://weblogs.java.net/blog/ss141213/examples/jpa_acc/entities/src/example/entity/UserCredential.java">UserCredential.java</a><br />
In my previous articles I have discussed about structure of an entity bean class. So I am not going to repeat them here.</p>

<p><u>Step #2: Define a persistence unit</u> in persistence.xml<br />
<pre>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"&gt<br />
    &lt;persistence-unit name ="pu1" transaction-type="RESOURCE_LOCAL"/&gt;<br />
&lt;/persistence&gt;</pre></p>

<p>Points to note about this persistence.xml are:</p>

<p>1) One persistence.xml can be used to define multiple PUs, but in this case we have defined only one PU by name pu1.</p>

<p>2) We need not specify any elements/attributes other than <strong>transaction-type</strong>, as the default values are just fine. By default the entity manager's transaction type is JTA. Since Application Client Container is not required to support JTA, we can not use JTA entity managers in this example. So we have set it to <strong>RESOURCE_LOCAL</strong> here.</p>

<p>3) There is no need to enumerate all the entity bean class names inside because we are defining only one PU in this persistence.xml and we will be packaging the entity classes along with this persistence.xml in a jar file, so container can discover all the entity beans. </p>

<p><u>Step #3: Write</u> <a href="http://weblogs.java.net/blog/ss141213/examples/jpa_acc/appclient/src/example/client/Main.java">Client.java</a><br />
Points to note about this appclient are that:</p>

<p>1) It declares dependency on the PersistenceUnit using @PersistenceUnit as shown below:</p>

<p><strong>@PersistenceUnit private static EntityManagerFactory emf;</strong></p>

<p>Also note that, the field ucm is <strong>static</strong>. More discussion on this further below. Secondly, there is only one PU visible to this application client, hence there is <strong>no</strong> need to specify the unitName attribute in @PersistenceUnit.</p>

<p>2) It must be a <strong>public</strong> class because it will be used by ACC which does not belong to the package of this class.</p>

<p>3) We also need to write a <a href="http://weblogs.java.net/blog/ss141213/examples/jpa_acc/appclient/manifest.mf">manifest.mf</a> file which must contain the name of the class containing the main().</p>

<p>4) The rest of the client class is simple. It creates an EntityManager using the injected EntityManagerFactory. It closes it at the end of the application. Since we can't use JTA, the client uses EntityTransaction API to manage transactions.</p>

<p>5) There is no need to write application-client.xml because it is optional. Java EE 5 compatible platform can discover appclient.jar's module type because it contains META-INF/MANIFEST.MF with a Main-Class attribute.</p>

<p><u>Step #4: Build and package the application</u> using <a href="http://weblogs.java.net/blog/ss141213/examples/jpa_acc/build.xml">build.xml</a><br />
When using entity beans in appclient, we have two packaging options:<br />
<strong>Option #1</strong>: package the entity beans and the persistence.xml in a jar file (say) entities.jar. Package the appclient main class along with its manifest.mf in a separate jar (say) appclient.jar. Put both these jars into an ear file. So the final ear file looks like this:<br />
<pre>jpa_acc_option1.ear<br />
     lib/entities.jar (contains only entity classes)<br />
     appclient.jar (contains only client main class and manifest file)</pre></p>

<p>Since the entities.jar is placed in the EAR lib directory, it is automatically added to CLASSPATH while running the appclient. So, no need to use Class-Path manifest entry.</p>

<p><strong>Option #2</strong>: package the entity beans and the persistence.xml in the appclient.jar along with appclient main class. <em>No need to make an ear file in this case, as we can just deploy the appclient.jar</em>. The appclient.jar contains following entries:<br />
<pre>appclient.jar:<br />
        META-INF/MANIFEST.MF (this contains Main-Class attribute)<br />
        META-INF/persistence.xml<br />
        example/client/Main.class<br />
        example/entity/UserCredential.class</pre></p>

<p>To demonstrate this, there are two build targets, viz: build-app1 and build-app2. The third build target internally call these two targets. Same goes for deploy and verify targets.</p>

<p></em>Both of the packaging alternatives discussed here are completely portable. It is upto you to decide which of the options you want to use.</em> </p>

<p><u>Step #5: Run the application</u><br />
As we mentioned, there are two different applications here. Depending on which application you want to use, the option passed to <strong>appclient</strong> command is slightly different as the name of the generated jar file is different.<br />
To run the first application client:<br />
$GLASSFISH_HOME/bin/appclient -client $GLASSFISH_HOME/domains/domain1/generated/xml/j2ee-apps/jpa_acc_option1/jpa_acc_option1Client.jar foo bar<br />
                                                                                <br />
To run the second application client (see different generated jar file name):<br />
$GLASSFISH_HOME/bin/appclient -client $GLASSFISH_HOME/domains/domain1/generated/xml/j2ee-modules/jpa_acc_option2/jpa_acc_option2Client.jar foo bar</p>

<p><u>Use of Java2DB</u><br />
Please see I don't have instructions to create tables etc. I like to use<br />
a feature called <a href="http://blogs.sun.com/roller/page/java2dbInGlassFish#automatic_table_generation_feature_in">Java2DB</a> in my development environment. Although there are more than one way of using Java2DB, I like to use it by passing --createtables option to asadmin deploy command. See build.xml for more info. This feature is specific to Sun's app server.</p>

<p><u>Why injected field or method must be static in application client?</u><br />
When we package the application client, we specified the main class name using Main-Class attribute in manifest file. The entry point for an Applicaiton Client component is the static main method of that main class, so there is no instance.  <br />
ACC does not create any instance of that class. So the injected fields or methods have to be static. </p>

<p><u>Software Required</u><br />
An <a href="https://glassfish.dev.java.net/javaee5/persistence/entity-persistence-support.html">implementation</a> of the Java Persistence API is being done in <a href="http://java.sun.com/javaee/glassfish/">GlassFish</a> project. GlassFish was supporting Java Persistence API in EJB and Web containers for quite some time now. Only recently, we have just integrated the Java Persistence API support in Application Client Container. As I am writing this blog, we still have not promoted a build that has this change. So you have to use one of the latest <a href="https://glassfish.dev.java.net/public/downloadsindex.html#Nightly_binary_builds">nightly builds</a> to run this example. <br />
Although I am using GlassFish to build and run this sample, atmost you have to do some minor confiuration to persistence.xml and build.xml to make this app build and run in any other application server that supports Java EE 5 specification. This sample also uses a proprietary feature called Java2DB. But that does not make this a non-portable application as I am using it only during deployment.</p>

<p>Hope you found this example useful. </p>

<p>More examples of <a href="http://technorati.com/tag/glassfish" rel="tag">glassfish</a> <a href="http://technorati.com/tags/persistence" rel="tag">persistence</a></p>]]>

</content>
</entry>
<entry>
<title>When can I use hibernate as EJB3 persistence provider in GlassFish</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/ss141213/archive/2006/01/when_can_i_use.html" />
<modified>2006-06-09T00:45:50Z</modified>
<issued>2006-01-17T09:08:55Z</issued>
<id>tag:weblogs.java.net,2006:/blog/ss141213/298.3952</id>
<created>2006-01-17T09:08:55Z</created>
<summary type="text/plain">A number of folks have asked me question about using Hibernate in GlassFish. Read on to know the state of things...</summary>
<author>
<name>ss141213</name>

<email>Sanjeeb.Sahoo@Sun.COM</email>
</author>
<dc:subject>J2EE</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/ss141213/">
<![CDATA[<p>Can I use <a href="http://hibernate.org">Hibernate</a> in <a href="http://glassfish.dev.java.net">GlassFish</a>? is a question I have been asked several times in recent past? Well, the answer is <strong>Yes & No(as of now)</strong>, depending on what you are trying to use it as. By the way I must clarify, it's a NO only temporarily. Let's understand why:</p>

<p><u>Yes:</u><br />
If you want to use Hibernate as yet another persistence framework, there is already a nice and detailed posting about <a href="http://wiki.java.net/bin/view/Projects/ConfigureHibernate">how to use hibernate in GlassFish</a>. That article shows how to use Hibernate session APIs, hibernate O/R mapping XML files etc. It does not talk about using Hibernate as an <strong>EJB 3.0</strong> persistence provider. That's the reason you find so many configuration steps mentioned in that article. </p>

<p><u>No:</u><br />
If you are trying to use Hibernate as an <strong>EJB 3.0</strong> persistence provider, it is right now not possible. I must say, it's only a <strong>temporary no</strong> because of the mismatch in interfaces between GlassFish and Hibernate. When I say using Hibernate as an EJB 3.0 persistence provider, what I mean is that user is using <a href="https://glassfish.dev.java.net/source/browse/glassfish/persistence-api/src/java/javax/persistence/">EJB 3.0 persistence API(javax.persistence) classes</a>. e.g. using @persistenceContext to inject an EntityManager, @Entity to annotate POJO classes as entity beans, persistence.xml to configure a persistence units etc. as demonstrated in <a href="http://weblogs.java.net/blog/ss141213/archive/2005/12/using_java_pers.html"> in this example</a> as opposed to using Hibernate session management APIs, Hibernate O/R mapping XML file to convert their POJO class to an entity bean etc. As you probably know the <a href="http://jcp.org/en/jsr/detail?id=220">EJB 3.0 (JSR 220)</a> spec defines a <strong>S</strong>ervice <strong>P</strong>rovider <strong>I</strong>nterface(SPI) to plug in a compliant persistence provider to a  Java EE 5 container like GlassFish. These SPI classes are part of <a href="https://glassfish.dev.java.net/source/browse/glassfish/persistence-api/src/java/javax/persistence/spi/">javax.persistence.spi</a> package. If you look at the revision history of the EJB 3 Persistence(a.k.a. Java Persistence API) spec, you will see that (unfortunately) the SPI has been changing quite a lot while the spec is being finalized. So it is hard for any two different projects to keep in synch with each other. Now that the final draft of the EJB 3 spec has been proposed, hopefully(!) we have a stable interface that both GlassFish and Hibernate can soon implement to achieve this pluggability.</p>

<p><u>EJB 3.0 Persistence SPI</u><br />
The SPI classes are part of <a href="https://glassfish.dev.java.net/source/browse/glassfish/persistence-api/src/java/javax/persistence/spi/">javax.persistence.spi</a> package. Users don't have to know about this package while using Java Persistence API inside a container. It is used by the container and persistence provider to provide the necessary pluggability. This is indeed good news for developers as they can use a <strong>combination</strong> of their favorite Java EE container with their favorite persistence provider without sacrificing portability of their applications. Some other day I shall talk more the SPI and issues around it.</p>

<p><u>Some EJB 3.0 Persistence API related resources:</u></p>

<p><a href="http://weblogs.java.net/blog/ss141213/archive/2005/12/using_java_pers.html">Introduction to using Java Persistence API in Java EE</a><br />
Latest <a href="https://glassfish.dev.java.net/public/downloadsindex.html">builds</a> of GlassFish where an open source implementation of this spec is being done.<br />
<a href="https://glassfish.dev.java.net/javaee5/persistence/entity-persistence-support.html">GlassFish persistence project</a></p>

<p>More articles about <a href="http://technorati.com/tag/glassfish" rel="tag">glassfish</a> <a href="http://technorati.com/tag/persistence" rel="tag">persistence</a></p>]]>

</content>
</entry>

</feed>