<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7994778055369999579</id><updated>2011-09-07T00:24:53.728-07:00</updated><category term='datasources jpa eclipselink'/><category term='jpa xmltype eclipselink oracle xml'/><category term='eclipselink moxy jaxb spring webservices'/><category term='toplinkgrid'/><category term='eclipselink spring'/><category term='eclipselink jpa sql query'/><title type='text'>On Persistence</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>17</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-4226575485241836052</id><published>2011-08-30T12:03:00.000-07:00</published><updated>2011-08-30T12:11:03.065-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='jpa xmltype eclipselink oracle xml'/><title type='text'>Mapping XMLTYPE</title><content type='html'>A recent posting on the TopLink Forum made it clear that previous descriptions of how to map a JPA entity attribute of type org.w3c.dom.Document to an Oracle database XMLTYPE column didn't provide enough information for schema (DDL) generation.  So I thought I'd post an example that does.  In the current 2.3.0 release of EclipseLink a mapping to XMLTYPE must be configured programatically through a descriptor customizer but declarative annotation and XML configuration support is scheduled for an upcoming release.&lt;br /&gt;&lt;br /&gt;Here's a simple entity with an XML document 'resume' attribute:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: java; highlight: [10,16]"&gt;import javax.persistence.Entity;&lt;br /&gt;import javax.persistence.GeneratedValue;&lt;br /&gt;import javax.persistence.Id;&lt;br /&gt;import javax.persistence.Table;&lt;br /&gt;&lt;br /&gt;import org.eclipse.persistence.annotations.Customizer;&lt;br /&gt;import org.w3c.dom.Document;&lt;br /&gt;&lt;br /&gt;@Entity&lt;br /&gt;@Customizer(XMLTypeAttributeCustomizer.class)&lt;br /&gt;public class JobCandidate {&lt;br /&gt;	@Id&lt;br /&gt;	@GeneratedValue&lt;br /&gt;	private long id;&lt;br /&gt;&lt;br /&gt;	private Document resume;&lt;br /&gt;&lt;br /&gt;	public long getId() {&lt;br /&gt;		return id;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	public void setId(final long id) {&lt;br /&gt;		this.id = id;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	public Document getMessage() {&lt;br /&gt;		return resume;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	public void setMessage(Document message) {&lt;br /&gt;		this.resume = message;&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And here is a customizer class that will redefine the mapping for the resume attribute to be an EclipseLink DirectToXMLTypeMapping:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: java; highlight: [13]"&gt;import org.eclipse.persistence.config.DescriptorCustomizer;&lt;br /&gt;import org.eclipse.persistence.descriptors.ClassDescriptor;&lt;br /&gt;import org.eclipse.persistence.mappings.xdb.DirectToXMLTypeMapping;&lt;br /&gt;&lt;br /&gt;public class XMLTypeAttributeCustomizer implements DescriptorCustomizer {&lt;br /&gt;	@Override&lt;br /&gt;	public void customize(final ClassDescriptor descriptor) throws Exception {&lt;br /&gt;		// Remove JPA default Basic mapping&lt;br /&gt;		descriptor.removeMappingForAttributeName("resume");&lt;br /&gt;		final DirectToXMLTypeMapping mapping = new DirectToXMLTypeMapping();&lt;br /&gt;		mapping.setAttributeName("resume");&lt;br /&gt;		mapping.setFieldName("RESUME");&lt;br /&gt;		mapping.getField().setColumnDefinition("sys.XMLTYPE");&lt;br /&gt;		descriptor.addMapping(mapping);&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The hightlighted line sets the database type of the mapping which is used by EclipseLink DDL generation and produces:&lt;br /&gt;&lt;pre&gt;[EL Fine]: CREATE TABLE JOBCANDIDATE (ID NUMBER(19) NOT NULL, RESUME sys.XMLTYPE, PRIMARY KEY (ID))&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-4226575485241836052?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/4226575485241836052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=4226575485241836052' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/4226575485241836052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/4226575485241836052'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2011/08/mapping-xmltype.html' title='Mapping XMLTYPE'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-5866740385661725971</id><published>2011-07-28T11:30:00.000-07:00</published><updated>2011-07-28T11:36:20.944-07:00</updated><title type='text'>GlassFish 3.1.1 Ships with EclipseLink 2.3!</title><content type='html'>GlassFish 3.1.1 shipped with EclipseLink 2.3 today!  Check out my post on the &lt;a href="http://eclipselink.blogspot.com/2011/07/glassfish-3.html"&gt;EclipseLink Team Blog&lt;/a&gt; for details.&lt;br /&gt;&lt;br /&gt;Shaun Smith, EclipseLink Team&lt;br /&gt;@shaunmsmith&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-5866740385661725971?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/5866740385661725971/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=5866740385661725971' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/5866740385661725971'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/5866740385661725971'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2011/07/glassfish-311-ships-with-eclipselink-23.html' title='GlassFish 3.1.1 Ships with EclipseLink 2.3!'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-1760107193383411034</id><published>2011-03-01T12:02:00.000-08:00</published><updated>2011-03-01T12:02:14.834-08:00</updated><title type='text'>The Poetry of Google Translated Twitter</title><content type='html'>&lt;a href="http://java-persistence.blogspot.com/"&gt;Doug Clarke&lt;/a&gt; recently setup a Google Reader aggregator that included a search of Twitter for the term "JPA".  Some of the messages are not in English but Google Reader is happy to translate them.  Unfortunately, or maybe fortunately in this case, mechanical translation isn't perfect and sometimes results in what feels like &lt;a href="http://en.wikipedia.org/wiki/Free_verse"&gt;free verse&lt;/a&gt; poetry.&lt;br /&gt;&lt;br /&gt;Here's a sample:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;JPA is the itches of God&lt;br /&gt;&lt;/li&gt;&lt;li&gt;I eat, jpa back. a kiss that cheese is my: *&lt;br /&gt;&lt;/li&gt;&lt;li&gt;In JPA I do not feel hungry. I have to live there.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-1760107193383411034?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/1760107193383411034/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=1760107193383411034' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/1760107193383411034'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/1760107193383411034'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2011/03/poetry-of-google-translated-twitter.html' title='The Poetry of Google Translated Twitter'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-1480975761394394790</id><published>2010-07-05T12:05:00.000-07:00</published><updated>2010-07-06T05:47:18.581-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipselink jpa sql query'/><title type='text'>EclipseLink JPA Native Constructor Queries</title><content type='html'>I saw a &lt;a href="http://www.coderanch.com/t/501617/ORM/java/entity-loading-blues"&gt;posting over on JavaRanch&lt;/a&gt; from someone wanting to return JavaBean results from a Native SQL query in JPA.  Turns out this is pretty easily done with EclipseLink and I just happen to have already written a utility class for just this purpose so I thought I'd post it.  &lt;br /&gt;&lt;br /&gt;You can configure a native SQL query to return POJOs in a single line of code using the JavaBeanResult utility class:&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt;   JavaBeanResult.setQueryResultClass(query, SomeBeanClass.class); &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;This will install an EclipseLink query redirector which will intercept the SQL query results and build JavaBean objects from them.&lt;br /&gt;&lt;br /&gt;The JavaBeanResult utility class will do the job but it relies on the developer to align the field selected in their SQL query with the constructor arguments for their bean.  For example, for the code below to work, SupplierBean must have a constructor with three arguments with types compatible with the SQL result types for columns id, name, and version.  JavaBeanResult uses the EclipseLink ConversionManager to convert each SQL result value to the declared type of the corresponding constructor argument.  If it can't you'll get an exception.  &lt;br /&gt;&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt;       Query query = getEntityManager()  &lt;br /&gt;          .createNativeQuery("SELECT ID, NAME, VER FROM SUPPLIER");  &lt;br /&gt;       JavaBeanResult.setQueryResultClass(query, SupplierBean.class);  &lt;br /&gt;       List&amp;lt;SupplierBean&amp;gt; results = query.getResultList();  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt;    public SupplierBean(int id, String name, Long version) {  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;--Shaun&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Complete source for JavaBeanResult.java:&lt;br /&gt;&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; /*******************************************************************************  &lt;br /&gt;  * Copyright (c) 2010 Oracle. All rights reserved.  &lt;br /&gt;  * This program and the accompanying materials are made available under the   &lt;br /&gt;  * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0   &lt;br /&gt;  * which accompanies this distribution.   &lt;br /&gt;  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html  &lt;br /&gt;  * and the Eclipse Distribution License is available at   &lt;br /&gt;  * http://www.eclipse.org/org/documents/edl-v10.php.  &lt;br /&gt;  *   &lt;br /&gt;  * @author shsmith  &lt;br /&gt;  ******************************************************************************/  &lt;br /&gt; package org.eclipse.persistence.example.jpa.nativesql.constructor;  &lt;br /&gt; import java.lang.reflect.Constructor;  &lt;br /&gt; import java.lang.reflect.InvocationTargetException;  &lt;br /&gt; import java.util.ArrayList;  &lt;br /&gt; import java.util.List;  &lt;br /&gt; import javax.persistence.Query;  &lt;br /&gt; import org.eclipse.persistence.exceptions.ConversionException;  &lt;br /&gt; import org.eclipse.persistence.internal.helper.ConversionManager;  &lt;br /&gt; import org.eclipse.persistence.internal.sessions.AbstractRecord;  &lt;br /&gt; import org.eclipse.persistence.internal.sessions.AbstractSession;  &lt;br /&gt; import org.eclipse.persistence.jpa.JpaHelper;  &lt;br /&gt; import org.eclipse.persistence.queries.DatabaseQuery;  &lt;br /&gt; import org.eclipse.persistence.queries.QueryRedirector;  &lt;br /&gt; import org.eclipse.persistence.sessions.Record;  &lt;br /&gt; import org.eclipse.persistence.sessions.Session;  &lt;br /&gt; /***  &lt;br /&gt;  * This class is a simple query redirector that intercepts the result of a  &lt;br /&gt;  * native query and builds an instance of the specified JavaBean class from each  &lt;br /&gt;  * result row. The order of the selected columns musts match the JavaBean class  &lt;br /&gt;  * constructor arguments order.  &lt;br /&gt;  *   &lt;br /&gt;  * To configure a JavaBeanResult on a native SQL query use:  &lt;br /&gt;  *    JavaBeanResult.setQueryResultClass(query, SomeBeanClass.class); &lt;br /&gt;  * where query is either a JPA SQL Query or native EclipseLink DatabaseQuery.  &lt;br /&gt;  *   &lt;br /&gt;  * @author shsmith  &lt;br /&gt;  *   &lt;br /&gt;  */  &lt;br /&gt; public final class JavaBeanResult implements QueryRedirector {  &lt;br /&gt;    private static final long serialVersionUID = 3025874987115503731L;  &lt;br /&gt;    protected Class&amp;lt;?&amp;gt; resultClass;  &lt;br /&gt;    public static void setQueryResultClass(Query query, Class&amp;lt;?&amp;gt; resultClass) {  &lt;br /&gt;       JavaBeanResult javaBeanResult = new JavaBeanResult(resultClass);  &lt;br /&gt;       DatabaseQuery databaseQuery = JpaHelper.getDatabaseQuery(query);  &lt;br /&gt;       databaseQuery.setRedirector(javaBeanResult);  &lt;br /&gt;    }  &lt;br /&gt;    public static void setQueryResultClass(DatabaseQuery query,  &lt;br /&gt;          Class&amp;lt;?&amp;gt; resultClass) {  &lt;br /&gt;       JavaBeanResult javaBeanResult = new JavaBeanResult(resultClass);  &lt;br /&gt;       query.setRedirector(javaBeanResult);  &lt;br /&gt;    }  &lt;br /&gt;    protected JavaBeanResult(Class&amp;lt;?&amp;gt; resultClass) {  &lt;br /&gt;       this.resultClass = resultClass;  &lt;br /&gt;    }  &lt;br /&gt;    @SuppressWarnings("unchecked")  &lt;br /&gt;    public Object invokeQuery(DatabaseQuery query, Record arguments,  &lt;br /&gt;          Session session) {  &lt;br /&gt;       List&amp;lt;Object&amp;gt; results = new ArrayList&amp;lt;Object&amp;gt;();  &lt;br /&gt;       try {  &lt;br /&gt;          Constructor&amp;lt;?&amp;gt; javaBeanClassConstructor =   &lt;br /&gt;             (Constructor&amp;lt;?&amp;gt;) resultClass.getDeclaredConstructors()[0];  &lt;br /&gt;          Class&amp;lt;?&amp;gt;[] constructorParameterTypes =   &lt;br /&gt;             javaBeanClassConstructor.getParameterTypes();  &lt;br /&gt;          List&amp;lt;Object[]&amp;gt; rows = (List&amp;lt;Object[]&amp;gt;) query.execute(  &lt;br /&gt;                (AbstractSession) session, (AbstractRecord) arguments);  &lt;br /&gt;          for (Object[] columns : rows) {  &lt;br /&gt;             Object[] constructorArgs = new Object[constructorParameterTypes.length];  &lt;br /&gt;             if (columns.length != constructorParameterTypes.length) {  &lt;br /&gt;                throw new ColumnParameterNumberMismatchException(  &lt;br /&gt;                      resultClass);  &lt;br /&gt;             }  &lt;br /&gt;             for (int j = 0; j &amp;lt; columns.length; j++) {  &lt;br /&gt;                Object columnValue = columns[j];  &lt;br /&gt;                Class&amp;lt;?&amp;gt; parameterType = constructorParameterTypes[j];  &lt;br /&gt;                // convert the column value to the correct type--if possible  &lt;br /&gt;                constructorArgs[j] = ConversionManager.getDefaultManager()  &lt;br /&gt;                      .convertObject(columnValue, parameterType);  &lt;br /&gt;             }  &lt;br /&gt;             results.add(javaBeanClassConstructor.newInstance(constructorArgs));  &lt;br /&gt;          }  &lt;br /&gt;       } catch (ConversionException e) {  &lt;br /&gt;          throw new ColumnParameterMismatchException(e);  &lt;br /&gt;       } catch (IllegalArgumentException e) {  &lt;br /&gt;          throw new ColumnParameterMismatchException(e);  &lt;br /&gt;       } catch (InstantiationException e) {  &lt;br /&gt;          throw new ColumnParameterMismatchException(e);  &lt;br /&gt;       } catch (IllegalAccessException e) {  &lt;br /&gt;          throw new ColumnParameterMismatchException(e);  &lt;br /&gt;       } catch (InvocationTargetException e) {  &lt;br /&gt;          throw new ColumnParameterMismatchException(e);  &lt;br /&gt;       }  &lt;br /&gt;       return results;  &lt;br /&gt;    }  &lt;br /&gt;    public final class ColumnParameterMismatchException extends  &lt;br /&gt;          RuntimeException {  &lt;br /&gt;       private static final long serialVersionUID = 4752000720859502868L;  &lt;br /&gt;       public ColumnParameterMismatchException(Throwable t) {  &lt;br /&gt;          super(  &lt;br /&gt;             "Exception while processing query results-ensure column order matches constructor parameter order",  &lt;br /&gt;             t);  &lt;br /&gt;       }  &lt;br /&gt;    }  &lt;br /&gt;    public final class ColumnParameterNumberMismatchException extends  &lt;br /&gt;          RuntimeException {  &lt;br /&gt;       private static final long serialVersionUID = 1776794744797667755L;  &lt;br /&gt;       public ColumnParameterNumberMismatchException(Class&amp;lt;?&amp;gt; clazz) {  &lt;br /&gt;          super(  &lt;br /&gt;             "Number of selected columns does not match number of constructor arguments for: "  &lt;br /&gt;             + clazz.getName());  &lt;br /&gt;       }  &lt;br /&gt;    }  &lt;br /&gt; }  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-1480975761394394790?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/1480975761394394790/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=1480975761394394790' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/1480975761394394790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/1480975761394394790'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2010/07/eclipselink-jpa-native-constructor.html' title='EclipseLink JPA Native Constructor Queries'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-5891319481113152830</id><published>2010-04-16T08:55:00.000-07:00</published><updated>2010-04-21T09:26:26.387-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='toplinkgrid'/><title type='text'>CheckCacheThenDatabase in TopLink Grid</title><content type='html'>EclipseLink JPA has a number of useful &lt;a href="http://www.eclipse.org/eclipselink/api/2.0/org/eclipse/persistence/config/CacheUsage.html"&gt;query hints&lt;/a&gt; that allow you to query the cache rather than, or before, the database.  This is useful because if you know you've warmed up your cache you can execute queries for objects and yet not have to query the database.  &lt;br /&gt;&lt;br /&gt;As of TopLink 11gR1 (11.1.1.2.0) TopLink Grid doesn't support these hints but it's only a problem for the 'Grid Cache' configuration in which Coherence is used as a shared cache replacement.  In Grid Cache, only primary key queries are sent to Coherence and all other queries go to the database. In the 'Grid Read' and 'Grid Entity' configurations all read queries are directed to Coherence.&lt;br /&gt;&lt;br /&gt;I was recently asked how to get a query to CheckCacheThenDatabase with Grid Cache and came up with the &lt;span style="font-family: courier new; font-size: 10pt;"&gt;&lt;span style="color: rgb(0,0,0);"&gt;GridCacheQueryHelper&lt;/span&gt;&lt;/span&gt; utility class below.  It provides the static method &lt;span style="font-family: courier new; font-size: 10pt;"&gt;&lt;span style="color: rgb(0,0,0);"&gt;checkCacheThenDatabase&lt;/span&gt;&lt;/span&gt; which will adjust an EclipseLink JPA query so that it queries Coherence (if the query can be translated to a Filter) and if no results are found in Coherence then it queries the database.&lt;br /&gt;&lt;br /&gt;Configuring a query would look something like:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new; font-size: 10pt;"&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Query&amp;nbsp;query&amp;nbsp;=&amp;nbsp;em.createQuery(&lt;/span&gt;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;select&amp;nbsp;e&amp;nbsp;from&amp;nbsp;Employee&amp;nbsp;e&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GridCacheQueryHelper.checkCacheThenDatabase(query);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;Employee&amp;gt;&amp;nbsp;employees&amp;nbsp;=&amp;nbsp;query.getResultList();&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;NOTE: this code is based on how TopLink Grid 11.1.1.2.0 is implemented and may not work with future releases.&lt;br /&gt;&lt;br /&gt;--Shaun&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new; font-size: 10pt;"&gt;&lt;span style="color: rgb(63,95,191);"&gt;/**&lt;br /&gt;&amp;nbsp;*&amp;nbsp;Utility&amp;nbsp;class&amp;nbsp;that&amp;nbsp;provides&amp;nbsp;implementations&amp;nbsp;of&amp;nbsp;EclipseLink&amp;nbsp;&lt;br /&gt;&amp;nbsp;*&amp;nbsp;query&amp;nbsp;hints&amp;nbsp;for&amp;nbsp;use&amp;nbsp;with&amp;nbsp;TopLink&amp;nbsp;Grid&amp;nbsp;'Grid&amp;nbsp;Cache'&amp;nbsp;Configuration.&lt;br /&gt;&amp;nbsp;*&amp;nbsp;&lt;br /&gt;&amp;nbsp;*&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,159,191);"&gt;@author&lt;/span&gt;&lt;span style="color: rgb(63,95,191);"&gt;&amp;nbsp;shsmith&lt;br /&gt;&amp;nbsp;*&lt;br /&gt;&amp;nbsp;*/&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;GridCacheQueryHelper&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;static&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;void&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;checkCacheThenDatabase(Query&amp;nbsp;jpqlQuery)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;JpaHelper&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.getDatabaseQuery(jpqlQuery)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.setRedirector(&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;CoherenceCheckCacheThenDatabase());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;private&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;static&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;CoherenceCheckCacheThenDatabase&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;implements&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;QueryRedirector&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;Object&amp;nbsp;invokeQuery(DatabaseQuery&amp;nbsp;query,&amp;nbsp;Record&amp;nbsp;arguments,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Session&amp;nbsp;session)&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: rgb(63,127,95);"&gt;//&amp;nbsp;Create&amp;nbsp;appropriate&amp;nbsp;Coherence&amp;nbsp;Query&amp;nbsp;Redirector&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;QueryRedirector&amp;nbsp;redirector&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;(query.isReadObjectQuery())&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;redirector&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;ReadObjectFromCoherence();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;else&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;(query.isReadAllQuery())&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;redirector&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;ReadAllFromCoherence();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;else&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;{&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;throw&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;RuntimeException(&lt;/span&gt;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;CheckCacheThenDatabase&amp;nbsp;only&amp;nbsp;supported&amp;nbsp;on&amp;nbsp;ReadObject&amp;nbsp;and&amp;nbsp;ReadAll&amp;nbsp;Queries.&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: rgb(63,127,95);"&gt;//&amp;nbsp;If&amp;nbsp;nothing&amp;nbsp;returned&amp;nbsp;from&amp;nbsp;Coherence&amp;nbsp;then&amp;nbsp;query&amp;nbsp;database.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: rgb(63,127,95);"&gt;//&amp;nbsp;But&amp;nbsp;only&amp;nbsp;if&amp;nbsp;the&amp;nbsp;query&amp;nbsp;was&amp;nbsp;only&amp;nbsp;run&amp;nbsp;against&amp;nbsp;Coherence&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: rgb(63,127,95);"&gt;//&amp;nbsp;and&amp;nbsp;no&amp;nbsp;results&amp;nbsp;were&amp;nbsp;found.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;nbsp;results&amp;nbsp;=&amp;nbsp;(List)redirector.invokeQuery(query,&amp;nbsp;arguments,&amp;nbsp;session);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;((results.isEmpty())&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;(query.getDoNotRedirect()))&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;return&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;query.execute((AbstractSession)session,&amp;nbsp;(AbstractRecord)&amp;nbsp;arguments);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;else&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;return&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;&amp;nbsp;results;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-5891319481113152830?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/5891319481113152830/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=5891319481113152830' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/5891319481113152830'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/5891319481113152830'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2010/04/checkcachethendatabase-in-toplink-grid.html' title='CheckCacheThenDatabase in TopLink Grid'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-4064751203443301979</id><published>2010-03-16T07:04:00.000-07:00</published><updated>2010-03-16T08:47:18.726-07:00</updated><title type='text'>Running a SQL Script on startup in EclipseLink</title><content type='html'>Sometimes, when working with DDL generation it's useful to run a script to clean up the database first.  In Hibernate if you put a file called "import.sql" on your classpath its contents will be sent to the database.  Personally I'm not a fan of magic filenames but this can be a useful feature.&lt;br /&gt;&lt;br /&gt;There's no built in support for this in EclipseLink but it's easy to do thank's to EclipseLink's high extensibility.  Here's a quick solution I came up with: I simply register an event listener for the session postLogin event and in the handler I read a file and send each SQL statement to the database--nice and clean.  I went a little further and supported setting the name of the file as a persistence unit property.  You can specify this all in code or in the persistence.xml.  &lt;br /&gt;&lt;br /&gt;The ImportSQL class is configured as a SessionCustomizer through a persistence unit property which, on the postLogin event, reads the file identified by the "import.sql.file" property.  This property is also specified as a persistence unit property which is  passed to createEntityManagerFactory.  This example also shows how you can define and use your own persistence unit properties.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new; font-size: 10pt;"&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;import&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;org.eclipse.persistence.config.SessionCustomizer;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;import&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;org.eclipse.persistence.sessions.Session;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;import&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;org.eclipse.persistence.sessions.SessionEvent;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;import&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;org.eclipse.persistence.sessions.SessionEventAdapter;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;import&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;org.eclipse.persistence.sessions.UnitOfWork;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;class&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;ImportSQL&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;implements&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;SessionCustomizer&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;private&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;void&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;importSql(UnitOfWork&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;unitOfWork,&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;String&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;fileName)&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(63,127,95);"&gt;//&amp;nbsp;Open&amp;nbsp;file&lt;br /&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(63,127,95);"&gt;//&amp;nbsp;Execute&amp;nbsp;each&amp;nbsp;line,&amp;nbsp;e.g.,&lt;br /&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(63,127,95);"&gt;//&amp;nbsp;unitOfWork.executeNonSelectingSQL(&amp;quot;select&amp;nbsp;1&amp;nbsp;from&amp;nbsp;dual&amp;quot;);&lt;br /&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;@Override&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;void&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;customize(Session&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;session)&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;throws&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;Exception&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;session.getEventManager().addListener(&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;SessionEventAdapter()&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;@Override&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;void&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;postLogin(SessionEvent&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;event)&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;String&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;fileName&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;(String)&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;event.getSession().getProperty(&lt;/span&gt;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;import.sql.file&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;);&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;UnitOfWork&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;unitOfWork&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;event.getSession().acquireUnitOfWork();&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;importSql(unitOfWork,&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;fileName);&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;unitOfWork.commit()&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;});&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;hr/&gt;&lt;br /&gt;&lt;span style="font-family: courier new; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;static&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;void&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;main(String[]&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;args)&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;Map&amp;lt;String,&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;Object&amp;gt;&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;properties&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;HashMap&amp;lt;String,&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;Object&amp;gt;();&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(63,127,95);"&gt;//&amp;nbsp;Enable&amp;nbsp;DDL&amp;nbsp;Generation&lt;br /&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;properties.put(PersistenceUnitProperties.DDL_GENERATION,&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;PersistenceUnitProperties.DROP_AND_CREATE);&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;properties.put(PersistenceUnitProperties.DDL_GENERATION_MODE,&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;PersistenceUnitProperties.DDL_DATABASE_GENERATION);&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(63,127,95);"&gt;//&amp;nbsp;Configure&amp;nbsp;Session&amp;nbsp;Customizer&amp;nbsp;which&amp;nbsp;will&amp;nbsp;pipe&amp;nbsp;sql&amp;nbsp;file&amp;nbsp;to&amp;nbsp;db&amp;nbsp;before&amp;nbsp;DDL&amp;nbsp;Generation&amp;nbsp;runs&lt;br /&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;properties.put(PersistenceUnitProperties.SESSION_CUSTOMIZER,&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;model.ImportSQL&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;);&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;properties.put(&lt;/span&gt;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;import.sql.file&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;,&lt;/span&gt;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;/tmp/someddl.sql&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;);&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;EntityManagerFactory&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;emf&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;Persistence&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;.createEntityManagerFactory(&lt;/span&gt;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;employee&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;,&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;properties);&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-4064751203443301979?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/4064751203443301979/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=4064751203443301979' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/4064751203443301979'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/4064751203443301979'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2010/03/running-sql-script-on-startup-in.html' title='Running a SQL Script on startup in EclipseLink'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-4995430290484193212</id><published>2010-02-18T08:08:00.000-08:00</published><updated>2010-02-18T08:38:33.325-08:00</updated><title type='text'>EclipseLink @ OSGi DevCon &amp; UKOUG Coherence London SIG</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://jaxlondon.com/conferences/OSGiDevCon/"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 77px;" src="http://1.bp.blogspot.com/_0CCzDIfKf50/S31mpqVbI5I/AAAAAAAAAcE/S0vMD_udVdA/s400/subheader_osgi_devcon.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5439616790858245010" /&gt;&lt;/a&gt;Next week is a busy one for me in London with &lt;a href="http://eclipse.org/proposals/gemini/"&gt;Gemini&lt;/a&gt; and &lt;a href="http://www.eclipse.org/eclipselink"&gt;EclipseLink &lt;/a&gt;related talks at both the OSGi DevCon (held in conjunction with JAX London) and the UKOUG Coherence London SIG.&lt;br /&gt;&lt;br /&gt;At &lt;a href="http://jaxlondon.com/conferences/OSGiDevCon/"&gt;OSGi DevCon&lt;/a&gt; I'll be presenting &lt;a href="http://jaxlondon.com/conferences/trackssessions/?tid=1453#session-13378"&gt;Introducing the OSGi JPA Specification&lt;/a&gt; with Mike Kieth, the Gemini project lead, on the new specification and its reference implementation based on EclipseLink.  This spec is part of the OSGi Enterprise Specification which extends the core OSGi platform to address enterprise scenarios. &lt;br /&gt;&lt;br /&gt;At the &lt;a href="http://www.ukoug.org/calendar/show_event.jsp?id=4770"&gt;UKOUG Coherence London SIG&lt;/a&gt; I'll be talking about &lt;a href="http://www.oracle.com/technology/products/ias/toplink/tl_grid.html"&gt;TopLink Grid&lt;/a&gt; which integrates EclipseLink JPA with Oracle Coherence to support scaling JPA applications.  If you've ever wondered how do I take my Java EE/JPA application and scale it to a cluster of hundreds of servers, this is the talk for you!  As of now the session is fully booked but you can still get on the waiting list. ;-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-4995430290484193212?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/4995430290484193212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=4995430290484193212' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/4995430290484193212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/4995430290484193212'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2010/02/eclipselink-osgi-devcon-ukoug-coherence.html' title='EclipseLink @ OSGi DevCon &amp; UKOUG Coherence London SIG'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_0CCzDIfKf50/S31mpqVbI5I/AAAAAAAAAcE/S0vMD_udVdA/s72-c/subheader_osgi_devcon.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-364109598386715473</id><published>2009-06-29T08:44:00.001-07:00</published><updated>2009-06-29T08:44:14.002-07:00</updated><title type='text'>OSGi Persistence Slides from OSGi DevCon Europe 2009</title><content type='html'>Here are the slides to a short presentation I gave on persistence at OSGi DevCon Europe in Zurich.  I had 30 minutes and wanted to do a demo to show that EclipseLink is running nicely in OSGi--it was tough cramming all this in but I did it without a moment to spare. Enjoy the slides and if they spark some questions you can post them here on the blog or on the EclipseLink newsgroup at http://www.eclipse.org/newsportal/thread.php?group=eclipse.rt.eclipselink or the eclipselink-users mailing list.&lt;br /&gt;--Shaun&lt;div style="width:425px;text-align:left" id="__ss_1654794"&gt;&lt;a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/shaunmsmith/osgi-persistence-with-eclipselink?type=powerpoint" title="OSGi Persistence With EclipseLink"&gt;OSGi Persistence With EclipseLink&lt;/a&gt;&lt;object style="margin:0px" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=osgipersistencewitheclipselink-090629102411-phpapp01&amp;stripped_title=osgi-persistence-with-eclipselink" /&gt;&lt;param name="allowFullScreen" value="true"/&gt;&lt;param name="allowScriptAccess" value="always"/&gt;&lt;embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=osgipersistencewitheclipselink-090629102411-phpapp01&amp;stripped_title=osgi-persistence-with-eclipselink" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;"&gt;View more &lt;a style="text-decoration:underline;" href="http://www.slideshare.net/"&gt;documents&lt;/a&gt; from &lt;a style="text-decoration:underline;" href="http://www.slideshare.net/shaunmsmith"&gt;shaunmsmith&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-364109598386715473?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/364109598386715473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=364109598386715473' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/364109598386715473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/364109598386715473'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2009/06/osgi-persistence-slides-from-osgi.html' title='OSGi Persistence Slides from OSGi DevCon Europe 2009'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-9150525027736650937</id><published>2008-10-28T08:49:00.000-07:00</published><updated>2008-10-28T09:10:25.932-07:00</updated><title type='text'>Delegation vs. Inheritance</title><content type='html'>The question "how do I change the type of my object" in JPA comes up now and then because developers know that an object's class is typically derived from an discriminator column on the database.  They reason that if they can change the column value then class of the object can be changed.  But it's not that simple.&lt;br /&gt;&lt;br /&gt;What you're really trying to do is to change the class of an Entity object. Obviously this isn't something supported by Java nor by JPA. In EclipseLink it may be possible to hammer a discriminator column, invalidate the affected object in the cache, and then reread it. That could work but with a large number of caveats including ensuring you hold no references to the transformed object in your persistence context. &lt;br /&gt;&lt;br /&gt;Instead, I'd suggest that if your domain model includes the ability to change the class of an Entity you refactor your model to use a delegation/role modeling approach rather than using inheritance. This allows you to change roles at runtime and even to have multiple concurrent roles (e.g., person could have a fireman role as well as a spouse role) and would behave accordingly.&lt;br /&gt;&lt;br /&gt;Here's a simple example:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new; font-size: 10pt;"&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;enum&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;PetType&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;CAT&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;String&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;speak()&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;return&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;meow&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;;&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;}&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;},&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;DOG&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;String&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;speak()&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;return&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;woof&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;;&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;}&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;};&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;abstract&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;String&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;speak();&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new; font-size: 10pt;"&gt;&lt;span style="color: rgb(0,0,0);"&gt;@Entity&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;class&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;Pet&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;@Id&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;@GeneratedValue&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;private&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;int&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;id;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;private&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;String&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;name;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;Pet()&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;}&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;Pet(String&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;name)&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;super&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;();&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;this&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;.name&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;name;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;}&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;@Enumerated&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;private&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;PetType&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;type&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;PetType.CAT;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;...&lt;br /&gt;&lt;span style="font-family: courier new; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;public&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;String&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;speak()&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;return&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;this&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;.getType().speak();&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0,0,0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;em.getTransaction().begin();&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;Pet&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;pet&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;new&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;Pet(&lt;/span&gt;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;fluffy&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;);&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;System.out.println(pet.getName()&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;&amp;nbsp;is&amp;nbsp;a&amp;nbsp;&amp;quot;&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;pet.getType().toString()&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;&amp;nbsp;and&amp;nbsp;says&amp;nbsp;&amp;quot;&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;pet.speak());&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;em.persist(pet);&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;em.getTransaction().commit();&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;em.getTransaction().begin();&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;pet&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;=&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;em.find(Pet.&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(127,0,85);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(0,0,0);"&gt;,&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;pet.getId());&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;pet.setType(PetType.DOG);&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;System.out.println(pet.getName()&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;&amp;nbsp;is&amp;nbsp;now&amp;nbsp;a&amp;nbsp;&amp;quot;&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;pet.getType().toString()&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(42,0,255);"&gt;&amp;quot;&amp;nbsp;and&amp;nbsp;says&amp;nbsp;&amp;quot;&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;+&lt;/span&gt;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;pet.speak());&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(0,0,0);"&gt;em.getTransaction().commit();&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;fluffy is a CAT and says meow&lt;br /&gt;[EL Fine]: Connection(27582163)--UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?&lt;br /&gt; bind =&gt; [50, SEQ_GEN]&lt;br /&gt;[EL Fine]: Connection(27582163)--SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?&lt;br /&gt; bind =&gt; [SEQ_GEN]&lt;br /&gt;[EL Fine]: Connection(27582163)--INSERT INTO PET (ID, NAME, TYPE) VALUES (?, ?, ?)&lt;br /&gt; bind =&gt; [101, fluffy, 0]&lt;br /&gt;fluffy is now a DOG and says woof&lt;br /&gt;[EL Fine]: Connection(27582163)--UPDATE PET SET TYPE = ? WHERE (ID = ?)&lt;br /&gt; bind =&gt; [1, 101]&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;One more thing&lt;/h4&gt;You could also implement methods on the PetType that took the Pet object and called back to the appropriate Pet method depending on the PetType.  All in all this is a pretty flexible solution.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-9150525027736650937?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/9150525027736650937/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=9150525027736650937' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/9150525027736650937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/9150525027736650937'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2008/10/delegation-vs-inheritance.html' title='Delegation vs. Inheritance'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-3136422307100079883</id><published>2008-05-26T08:39:00.000-07:00</published><updated>2008-05-26T09:08:14.699-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipselink spring'/><title type='text'>EclipseLink at SpringOne 2008</title><content type='html'>This year I'll be at SpringOne again and this time I'll be co-presenting with &lt;a href="http://springone.wiki-neon.adaptavist.com/display/SpringOne08/Rob+Harrop"&gt;Rob Harrop&lt;/a&gt; of SpringSource about using cool features of &lt;a href="http://springone.wiki-neon.adaptavist.com/display/SpringOne08/EclipseLink--High+Performance+Persistence+for+Spring"&gt;EclipseLink with Spring&lt;/a&gt;.  I've blogged previously about using &lt;a href="http://onpersistence.blogspot.com/2008/04/eclipselink-moxy-in-spring-ws.html"&gt;EclipseLink MOXy with Spring Web Services&lt;/a&gt; but with EclipseLink implementing a number of persistence standards and having so many advanced features there are lots of ways you can leverage it from Spring.  We're going to dive into a few of the coolest features that differentiate EclipseLink from other persistence frameworks and show how you can use them in your Spring application.&lt;br /&gt;&lt;br /&gt;--Shaun&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-3136422307100079883?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/3136422307100079883/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=3136422307100079883' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/3136422307100079883'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/3136422307100079883'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2008/05/eclipselink-at-springone-2008.html' title='EclipseLink at SpringOne 2008'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-1644510579208920272</id><published>2008-05-16T12:46:00.000-07:00</published><updated>2008-05-16T13:03:25.184-07:00</updated><title type='text'>Best JavaOne Shirt Ever!</title><content type='html'>If you've been to JavaOne in the last couple of years you'll have noticed the free custom T-Shirt booth.  It's always jammed so I never paid it much attention.  This year I happened to walk by it right after the trade show floor had opened--and the line was only 5 or 6 people--so I jumped in line!  This year you had to complete an equation--remember this is a technology conference after all.  The equation was:&lt;br /&gt;&lt;br /&gt;"Java + _______ = _______".  &lt;br /&gt;&lt;br /&gt;Below you can see what I came up with. Best..(Free) T-Shirt...Ever!&lt;br /&gt;&lt;br /&gt;--Shaun &lt;br /&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_0CCzDIfKf50/SC3lwcEHubI/AAAAAAAAACE/-SwQ5h1BTEY/s1600-h/EclipseLink+T-Shirt+Full.jpg"&gt;&lt;img style="cursor: pointer;" src="http://4.bp.blogspot.com/_0CCzDIfKf50/SC3lwcEHubI/AAAAAAAAACE/-SwQ5h1BTEY/s400/EclipseLink+T-Shirt+Full.jpg" alt="" id="BLOGGER_PHOTO_ID_5201065765012748722" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;br /&gt;&lt;td&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_0CCzDIfKf50/SC3l4MEHucI/AAAAAAAAACM/cRawxxb8Gi0/s1600-h/EclipseLink+T-Shirt+Zoomed.jpg"&gt;&lt;img style="cursor: pointer;" src="http://3.bp.blogspot.com/_0CCzDIfKf50/SC3l4MEHucI/AAAAAAAAACM/cRawxxb8Gi0/s400/EclipseLink+T-Shirt+Zoomed.jpg" alt="" id="BLOGGER_PHOTO_ID_5201065898156734914" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-1644510579208920272?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/1644510579208920272/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=1644510579208920272' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/1644510579208920272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/1644510579208920272'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2008/05/best-javaone-shirt-ever.html' title='Best JavaOne Shirt Ever!'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_0CCzDIfKf50/SC3lwcEHubI/AAAAAAAAACE/-SwQ5h1BTEY/s72-c/EclipseLink+T-Shirt+Full.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-8293535149388462407</id><published>2008-05-16T10:57:00.000-07:00</published><updated>2008-05-16T13:16:07.545-07:00</updated><title type='text'>The 1st Irish Open Source Technology Conference</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.thechurch.ie/images/stories/gallery2/images_vert1.jpg"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 400px;" src="http://www.thechurch.ie/images/stories/gallery2/images_vert1.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://iotc.firstport.ie/"&gt;The Irish Open Source Technology Conference&lt;/a&gt; (IOTC) will be held June 18th-20th in Dublin and promises to be great event!  &lt;a href="http://www.irishdev.com/NewsArticle.aspx?id=6606"&gt;I'll be there&lt;/a&gt; to represent EclipseLink and the Eclipse Runtime Project that it's a part of. &lt;br /&gt;&lt;br /&gt;I'd been to the Irish Java Technology Conference last year which was also organized by Barry Alistair at &lt;a href="http://irishdev.com/"&gt;IrishDev.com&lt;/a&gt; and so I know IOTC will be great.  The conference venue was great, the speakers were top shelf (IMHO), and the Irish beer at the &lt;a href="http://www.thechurch.ie/"&gt; The Church&lt;/a&gt; was wonderful.&lt;br /&gt;&lt;br /&gt;This year they'll be doing live streaming of sessions so if you can't make it to Dublin you can still "attend" sessions.  Unfortunately the technology does not yet exist to stream the beer you should enjoy after a long day at the conference. ;-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-8293535149388462407?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/8293535149388462407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=8293535149388462407' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/8293535149388462407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/8293535149388462407'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2008/05/1st-irish-open-source-technology.html' title='The 1st Irish Open Source Technology Conference'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-5212095681101815732</id><published>2008-04-18T09:51:00.000-07:00</published><updated>2008-04-18T11:02:50.968-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipselink moxy jaxb spring webservices'/><title type='text'>EclipseLink MOXy in Spring-WS</title><content type='html'>I was reminded that I'd promised an example of how to use EclipseLink MOXy in Spring Web Services so here we go.  Fortunately this isn't hard to do as Spring-WS abstracts the concept of a Marshaller and an Unmarshaller so you can plug in various diverse technologies.  One of those technologies supported "out of the box" is JAXB 2, and since EclipseLink MOXy implements JAXB 2 all we have to worry about is Spring configuration and just a little code.&lt;br /&gt;&lt;br /&gt;I've adapted one of the &lt;a href="http://www.oracle.com/technology/products/ias/toplink/preview/how-to/jaxb-compiler-xsd.html"&gt;Oracle TopLink 11g JAXB demos&lt;/a&gt; to use Spring for configuration and Spring-WS interfaces for marshalling/unmarshalling.  That demo describes how the code works so, for brevity, I'll assume you've read it. A link to the source for this updated demo is at the bottom of this posting.&lt;br /&gt;&lt;br /&gt;Marshalling/Unmarshalling is something you can do in a number of context in Spring-WS including handling WebService and JMS message payloads so once you see how MOXy JAXB is configured in this simple example you can use this knowledge in any Spring application that works with XML.&lt;br /&gt;&lt;h3&gt;Configuration--Spring applicationContext.xml&lt;/h3&gt;Since this is Spring we need an applicationContext.xml file in which to&lt;br /&gt;layout all your bean config.  At the bottom of the file (below) I&lt;br /&gt;declare two beans: marshallExample and unmarshallExample.&lt;br /&gt;marshallExample has a marshaller injected, and unmarshallExample has&lt;br /&gt;both a marshaller and unmarshaller injected.  Notice that the bean&lt;br /&gt;refs for both the marshaller and unmarshaller is the same bean&lt;br /&gt;"jaxbMarshaller"--I'll get to that in a moment.&lt;br /&gt;&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;beans &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmlns="http://www.springframework.org/schema/beans" &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; xsi:schemaLocation="http://www.springframework.org/schema/beans&lt;br /&gt;http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="contextPath" value="examples.jaxb.generated"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;bean id="marshallExample" class="examples.jaxb.marshall.MarshallGenerated"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="marshaller" ref="jaxbMarshaller"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/bean&amp;gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;bean id="unmarshallExample" class="examples.jaxb.unmarshall.UnmarshallGenerated"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="unmarshaller" ref="jaxbMarshaller"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="marshaller" ref="jaxbMarshaller"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/bean&amp;gt;&lt;br /&gt;&amp;lt;/beans&amp;gt;&lt;br /&gt;&lt;br /&gt;At the top of the file I declare "jaxbMarshaller" as an instance of the&lt;br /&gt;Spring-WS Jaxb2Marshaller class.  And I pass the property&lt;br /&gt;"contextPath" to it so that it knows what classes it is responsible for&lt;br /&gt;handing.  In this case "examples.jaxb.generated".  If you&lt;br /&gt;look in that package in the example source you'll see a jaxb.properties&lt;br /&gt;file.  The jaxb.properties file can be used to specify the JAXB&lt;br /&gt;implementation to use.  In this case the jaxb.properties file&lt;br /&gt;contains the single line:&lt;br /&gt;&lt;br /&gt;javax.xml.bind.context.factory = org.eclipse.persistence.jaxb.JAXBContextFactory&lt;br /&gt;&lt;br /&gt;This is how we plug in EclipseLink MOXy as the JAXB implementation to&lt;br /&gt;use.  The jaxb.properties file is standard JAXB, not Spring.&lt;br /&gt;If you take a look back at the OTN example you'll see the same&lt;br /&gt;file.  What Spring-WS adds is the Jaxb2Marshaller class and the&lt;br /&gt;generic interfaces it implements.  Unlike in JAXB where you obtain&lt;br /&gt;a JAXB Marshaller or Unmarshaller from a JAXBContext, Spring-WS does&lt;br /&gt;this behind the scenes.  Rather than exposing the objects it&lt;br /&gt;instead exposes marshall and unmarshall methods.  By not exposing&lt;br /&gt;these objects it makes it possible to swap out a JAXB marshaller for&lt;br /&gt;another kind of marshaller. And this is why jaxbMarshaller is used as&lt;br /&gt;both marshaller and unmarshaller in the unmarshallExampleBean.&lt;br /&gt;&lt;h3&gt;Bootstrapping Your Application&lt;/h3&gt;To use these beans you use the standard Spring bean lookup method, e.g.:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MarshallGenerated marshallGenerated = (MarshallGenerated) applicationContext&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;.getBean("marshallExample", MarshallGenerated.class);&lt;br /&gt;&lt;br /&gt;If you've got your applicationContext.xml right then the instance of&lt;br /&gt;MarshallGenerated that you get from Spring will be fully configured&lt;br /&gt;with an instance of Jaxb2Marshaller injected.&lt;br /&gt;&lt;br /&gt;To marshall or unmarshall you use the Spring Jaxb2Marshaller methods.  However the arguments to those methods are slightly different than those of a JAXB Marshaller or Unmarshaller and use javax.xml.transform.Source and javax.xml.transform.Result.  This is a pretty minor difference and was an easy change to the application code.&lt;br /&gt;&lt;h3&gt;Running the Example&lt;/h3&gt;To run the example you just need to download &lt;a href="http://shaunmsmith.googlepages.com/EclipseLinkMoxy-SpringWS.zip"&gt;EclipseLinkMoxy-SpringWS.zip&lt;/a&gt;, unzip, and edit the environment variables eclipselink.home, spring.home, and spring-ws.home at the top of the ANT build.xml file.  Once you have those set you can run ANT to build and run.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-5212095681101815732?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/5212095681101815732/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=5212095681101815732' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/5212095681101815732'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/5212095681101815732'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2008/04/eclipselink-moxy-in-spring-ws.html' title='EclipseLink MOXy in Spring-WS'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-2818558463264893864</id><published>2008-04-08T07:54:00.000-07:00</published><updated>2008-04-08T08:13:42.819-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='datasources jpa eclipselink'/><title type='text'>Passing DataSources to EclipseLink JPA</title><content type='html'>When you hear the same question twice it's time to blog the answer so the third time it comes up you can point to the blog. ;-)  This time it's whether you can pass a DataSource to EclipseLink JPA and have it use that instead of what's configured in persistence.xml (or perhaps not configured in persistence.xml).&lt;br /&gt;&lt;br /&gt;Yes, you can pass a DataSource.  Here's a code sample that illustrates creating a Derby DataSource and passing it as a property to createEntityManagerFactory.  Works like a charm.&lt;br /&gt;&lt;br /&gt;--Shaun&lt;br /&gt;&lt;br /&gt;private DataSource createDataSource() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClientDataSource dataSource = new ClientDataSource();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;dataSource.setServerName("localhost");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;dataSource.setPortNumber(1527);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;dataSource.setDatabaseName("sample");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;dataSource.setUser("app");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;dataSource.setPassword("app");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return dataSource;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private EntityManagerFactory getEntityManagerFactory() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (emf == null) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Map&lt;String, Object&gt; properties = new HashMap&lt;String, Object&gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;properties&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.put(PersistenceUnitProperties.NON_JTA_DATASOURCE,createDataSource());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;emf = Persistence.createEntityManagerFactory(PU_NAME, properties);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return emf;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-2818558463264893864?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/2818558463264893864/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=2818558463264893864' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/2818558463264893864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/2818558463264893864'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2008/04/eclipselink-and-datasources.html' title='Passing DataSources to EclipseLink JPA'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-3705132639797233787</id><published>2008-03-17T11:56:00.000-07:00</published><updated>2008-03-17T14:52:20.313-07:00</updated><title type='text'>EclipseLink is the JPA 2.0 Reference Implementation</title><content type='html'>I won't repeat the details here but you can check out the news over at the &lt;a href="http://eclipselink.blogspot.com/2008/03/eclipselink-to-provide-jpa-20-reference.html"&gt;EclipseLink Team Blog&lt;/a&gt; and at the &lt;a href="http://blogs.sun.com/theaquarium/entry/eclipselink_in_glassfish_v3_as"&gt;GlassFish Aquarium&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;This is great news for JPA 2.0!  And since &lt;a href="http://www.eclipse.org/eclipselink"&gt;EclipseLink &lt;/a&gt;shares the same source code "DNA" as TopLink Essentials, the JPA 1.0 reference implementation, migration for users of TopLink Essentials won't be difficult.  Especially since EclipseLink includes tools for migrating code and configuration files from TopLink Essentials and Oracle TopLink.&lt;br /&gt;&lt;br /&gt;IMHO, moving to EclipseLink is a no-brainer.  EclipseLink has all the functionality of TopLink Essentials plus advanced features like cache coordination and advanced mappings like &lt;a href="http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#How_to_Use_the_.40Converter_Annotation"&gt;Converters &lt;/a&gt;, &lt;a href="http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#Using_EclipseLink_JPA_Extensions_for_Returning_Policy"&gt;Returning Policies&lt;/a&gt;, and &lt;a href="http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#Using_EclipseLink_JPA_Extensions_for_Mapping"&gt;Basic Collections&lt;/a&gt;.   Check it out!&lt;br /&gt;&lt;br /&gt;--Shaun&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-3705132639797233787?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/3705132639797233787/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=3705132639797233787' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/3705132639797233787'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/3705132639797233787'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2008/03/eclipselink-is-jpa-20-reference.html' title='EclipseLink is the JPA 2.0 Reference Implementation'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-1341495165126395286</id><published>2008-01-30T07:05:00.000-08:00</published><updated>2008-01-30T08:30:40.468-08:00</updated><title type='text'>Welcome (Back?)</title><content type='html'>With the open sourcing of Oracle TopLink in the &lt;a href="http://www.eclipse.org/eclipselink/"&gt;EclipseLink (Eclipse Persistence Services) Project&lt;/a&gt; at Eclipse I thought I'd better get back to blogging and since my comments will be about more than TopLink I also thought it would be a good idea to move to a more general blog name.  So welcome to &lt;span style="font-weight: bold;"&gt;On Persistence&lt;/span&gt;!&lt;br /&gt;&lt;br /&gt;--Shaun&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-1341495165126395286?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/1341495165126395286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=1341495165126395286' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/1341495165126395286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/1341495165126395286'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2008/01/welcome-back.html' title='Welcome (Back?)'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7994778055369999579.post-5205653991255869446</id><published>2008-01-30T06:53:00.000-08:00</published><updated>2008-01-30T08:31:16.756-08:00</updated><title type='text'>Customizing EclipseLink JPA/ORM Relationship Joins</title><content type='html'>Sometimes you want to add join criteria in a one-to-one or one-to-many mapping with an arbitrary constraint.  There are a few situations in which you'd want to do this but I won't go into that here.  But hopefully when it happens to you you'll know how to deal with it in EclipseLink.&lt;br /&gt;&lt;br /&gt;As an example, let's consider a two class object model with classes A and B.  A has a one-to-one with B based on a foreign key relationship.  Let's say that we only ever want the one-to-one to B to resolve to an object if the B's status is "active".  What we need to do is ensure that the SQL query for B includes this constraint.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Behinds the Scenes&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When you define a one-to-one or one-to-many mapping in either JPA (e.g., @OneToOne) or using the EclipseLink &lt;a href="http://wiki.eclipse.org/EclipseLink/Development/200040/FunctionalSpec"&gt;native mapping format&lt;/a&gt;, behind the scenes EclipseLink builds a Mapping object.  In the Mapping object is an Expression that defines the selection criteria that will be used to resolve the object or objects that are the target of the mapping.  At runtime EclipseLink generates SQL from this Expression.  So the key to changing the SQL used in the join is to augment or change in some way this Expression.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Making it Work&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To get our hands on the Expression of the Mapping object we need to define a Descriptor Customizer.   In my TopLink blog I described how to &lt;a href="http://ontoplink.blogspot.com/2007/02/read-only-jpa-entities.html"&gt;define a TopLink customizer to make a class read-only&lt;/a&gt;.   We'll take the same approach here with EclipseLink.  There are only two things you need to do to get this working:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Create a customizer class that implements org.eclipse.persistence.internal.sessions.factories.DescriptorCustomizer&lt;/li&gt;&lt;li&gt;Associate the customizer with class A in the persistence.xml&lt;/li&gt;&lt;/ol&gt;Here's a customizer that adds a constraint on the "status" property of the target object (error handling left out for brevity):&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class ACustomizer implements DescriptorCustomizer {&lt;br /&gt;&lt;br /&gt; public void customize(ClassDescriptor desc) {&lt;br /&gt;     OneToOneMapping mapping = (OneToOneMapping) desc.getMappingForAttributeName("b");&lt;br /&gt;     Expression origExp = mapping.buildSelectionCriteria();&lt;br /&gt;     ExpressionBuilder b = origExp.getBuilder();&lt;br /&gt;     &lt;span style="font-weight: bold;"&gt;Expression constantExp = b.get("status").equal("active");&lt;/span&gt;&lt;br /&gt;     Expression newExp= origExp.and(constantExp);&lt;br /&gt;     mapping.setSelectionCriteria(newExp);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;In the customizer we get the ClassDescriptor associated with class A that EclipseLink built after processing all annotations and mapping files.  From it we get the OneToOneMapping for the "b" attribute.   And then we get the selection criteria expression that is based on the mappings.  From the Expression we get the ExpressionBuilder and proceed to build a new Expression that we "and" with the original Expression.  To finish up we set the selection criteria of the OneToOneMapping to the new Expression.&lt;br /&gt;&lt;br /&gt;To enable the use of the customizer you'll need to add a property to your persistence.xml.&lt;br /&gt;&lt;br /&gt;&amp;lt;properties&amp;gt;&lt;br /&gt;     &amp;lt;property name="eclipselink.descriptor.customizer.A"&lt;br /&gt;           value="model.ACustomizer"/&amp;gt;&lt;br /&gt;&lt;br /&gt;When I setup this customizer in my example I see the following SQL in the console when I try to read the B associated with an A:&lt;br /&gt;&lt;br /&gt;SELECT ID, STATUS FROM B WHERE ((ID = 2) AND (STATUS = 'active'))&lt;br /&gt;&lt;br /&gt;Cool--just what I wanted!&lt;br /&gt;&lt;br /&gt;--Shaun&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7994778055369999579-5205653991255869446?l=onpersistence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://onpersistence.blogspot.com/feeds/5205653991255869446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7994778055369999579&amp;postID=5205653991255869446' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/5205653991255869446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7994778055369999579/posts/default/5205653991255869446'/><link rel='alternate' type='text/html' href='http://onpersistence.blogspot.com/2008/01/customizing-eclipselink-jpaorm.html' title='Customizing EclipseLink JPA/ORM Relationship Joins'/><author><name>Shaun Smith</name><uri>http://www.blogger.com/profile/03444889032778621661</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
