While preparing for a workshop on the EJB 3.0 Persistence API that I will present later today, I decided – against all the instructions in demo-school and presentation-college – to make a last minute change: replace the Glassfish libraries from build 20 (december 2005) with the new Glassfish stand-alone Persistence implementation (see: https://glassfish.dev.java.net/downloads/persistence/JavaPersistence.html) (that is 2 Mb instead of 80 or so). What I did not count on, is that since the build I used before, there have been several changes in the Annotations used for defining the Object Relational Mapping. As a result, my demos did not function anymore, and some of the labs were rendered incorrect.

 

....
Using the most recent EJB 3.0 Persistence Specification document I tried to correct, one by one, the errors my compilation as well as runtime execution ran into. Here a summary of the changes I had to make:

@ID – no longer has any attributes. No more generate and generator attributes

@GeneratedValue – the following method is now used for specifying the fact that the value for an attribute during insert into the database should be retrieved from a database sequence:

<br />    @Id<br />    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator=&quot;ALS_PBR_SEQ&quot;)<br />    @Column<br />    public Long getId() {<br />        return id;<br />    } <br />

We also need to import two classes:

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

@NamedQuery – the attribute queryString is now simply called query.

@JoinTable – the attribute table (of type @Table) is dropped. Now we simply use name to specify the name of the JoinTable. For example:

@ManyToMany(cascade=CascadeType.ALL)<br />    @JoinTable(name = &quot;als_authorships&quot;, joinColumns = {<br />           @JoinColumn(name = &quot;atr_id&quot;)<br />       }, inverseJoinColumns = {<br />           @JoinColumn(name = &quot;bok_id&quot;)<br />       }) <br />

Then the persistence.xml underwent some changes:

We need to add the attribute version="1.0" to the persistence element:

&lt;persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot; version=&quot;1.0&quot;&gt;<br />&nbsp;

And the property-names were changed; instead of just jdbc.driver, jdbc.url etc., the standalone Glassfish Persistence implementation requires the property names to be prefixed with toplink.jdbc…. It does not seem likely that this change is a JSR-220 modification, it is more likely that this reflects an internal change in the Glassfish code.

&lt;properties&gt;<br />  &lt;property name=&quot;toplink.jdbc.driver&quot; value=&quot;&lt;database driver&gt;&quot;/&gt;<br />  &lt;property name=&quot;toplink.jdbc.url&quot; value=&quot;&lt;database url&gt;&quot;/&gt;<br />  &lt;property name=&quot;toplink.jdbc.user&quot; value=&quot;&lt;user&gt;&quot;/&gt;<br />  &lt;property name=&quot;toplink.jdbc.password&quot; value=&quot;&lt;password&gt;&quot;/&gt;<br />  &lt;property name=&quot;toplink.logging.level&quot; value=&quot;INFO&quot;/&gt;<br />&lt;/properties&gt; <br />

 

Since most of these changes seem improvements, I am not hugely disappointed. And I found about these just in time for my workshop.

 

Resources

 

http://trycatchfinally.blogspot.com/2006/01/experiments-with-ejb-30-id-annotation.html on how to get started with Glassfish Stand Alone persistence 

Java Community Process on EJB 3.0 Persistence 

Glassfish Reference Implementation of EJB 3.0 Persistence