<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Olaf&#039;s blog &#187; JPA</title>
	<atom:link href="http://olafsblog.sysbsb.de/category/jpa/feed/" rel="self" type="application/rss+xml" />
	<link>http://olafsblog.sysbsb.de</link>
	<description>Olaf&#039;s blog on software development and life</description>
	<lastBuildDate>Sat, 14 Aug 2010 20:39:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Modular development with OSGI about to be very, very popular &#8211; finally.</title>
		<link>http://olafsblog.sysbsb.de/modular-development-with-osgi-about-to-be-very-very-popular-finally/</link>
		<comments>http://olafsblog.sysbsb.de/modular-development-with-osgi-about-to-be-very-very-popular-finally/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 11:40:32 +0000</pubDate>
		<dc:creator>olaf</dc:creator>
				<category><![CDATA[J2EE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[OSGI]]></category>
		<category><![CDATA[System architecture]]></category>
		<category><![CDATA[eclipselink]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://olafsblog.sysbsb.de/?p=72</guid>
		<description><![CDATA[It&#8217;s quite exciting to see the tremendous progress in development tools, patterns, frameworks and libraries since the release of JAVA 1.0 in 1996.
Within just thirteen years, development improved from the first applets, from the dark ages of the first EJB standardization attempts and a lack of suitable development processes into an age where aspect oriented [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s quite exciting to see the tremendous progress in development tools, patterns, frameworks and libraries since the release of JAVA 1.0 in 1996.<br />
Within just thirteen years, development improved from the first applets, from the dark ages of the first EJB standardization attempts and a lack of suitable development processes into an age where aspect oriented programming, dependency injection and a freely available range of lightweight yet extremely powerful frameworks, libraries and API&#8217;s finally permitted the humble programmer to do what he always wanted to do &#8211; analyze problems, and elegantly write them down without spending all of his precious time on the syntax.</p>
<p>I would even go as far as saying that there was no object orientation before programming crosscutting concerns and using dependency injection became established mechanisms.<br />
Think about it: The original goal of OO is not to use inheritance, encapsulation, identity and polymorphism, but to express the <em>real world of things</em> &#8211; our reality &#8211; using an <em>abstract world of things</em>, while preserving most of the properties and relationships we observe in reality. </p>
<p>Before AOP, before being able to separate the description of things from creating, configurating and connecting concrete instances through dependency injection frameworks, this goal was hard to achieve.</p>
<h3>Modules larger than classes with OSGI</h3>
<p>Now however, we are about to reach a new stage in development of object orientation in JAVA: Developing modules that are <em>larger than classes</em>, modules which can, once properly identified, be developed independently using all the wonderful technology described beforehand. The technology used to achieve this has a name: <a href="http://en.wikipedia.org/wiki/OSGi">OSGI</a>. This technology has quite a long history of development, but a certain lack of elegance and light-weightiness barred this component model from becoming a real hit in the worldwide development community. This is about to change.<br />
<span id="more-72"></span></p>
<h3>Impact of OSGI on the development process</h3>
<p>Let me stress out here how important it is to be able to develop, manage and deploy such modules. The larger your system, the more developers your project involves, the longer you maintain it &#8211; you will always face the same problem: Developers concurrently working with party of the system that are directly or transitively connected will run into conflicts. You will have different parts of your system requiring different versions of the same library on the same class path. Changing one part of the system will always affect other parts of the system, most of the times in an unplanned fashion. </p>
<p>Test driven developments helps a lot along the way, but you still have a responsibility problem if there&#8217;s one team changing something and this causes a problem in a different part of the system, and dependency issues can be a real mess.</p>
<p>This is where OSGI can play out it&#8217;s strengths. Not only does it offer you complete, classloader-based module isolation. I believe the greatest benefit lies in the development process: Concurrent development is a lot easier with OSGI bundles than with a huge pile of tightly interconnected classes. You can have a lot of changes in the bundle, while exposing a relatively stable interface through which other components access your bundle&#8217;s services. Separation into OSGI bundles can bring the power of the SOA-Idea into &#8220;stand-alone&#8221; applications, without the massive overhead of connecting systems or components through, for example web services.</p>
<p>Of course, this concept has quite an impact on your way of thinking, since you will start to add a new level of decomposition: Which classes form tightly coupled components that could be isolated from other components and used as a service through a well-defined, slim and easy-to-use interface? </p>
<h3>OSGI about to &#8220;break through&#8221;</h3>
<p>Now, why am i so convinced that OSGI is about to finally become as common as using AOP or dependency injection? Because all the popular technologies are just about to embrace OSGI:</p>
<ul>
<li>
    <a href="http://www.jroller.com/habuma/entry/modular_java">Craig walls (Spring framework) has just finished his book an modular JAVA with the spring framework, featuring OSGI and Spring</a>, a very powerful combination.
 </li>
<li>
    <a href="http://it-republik.de/jaxenter/jax/sessions/jax/speaker/#3271">Doug Clarke</a> and <a href="http://it-republik.de/jaxenter/jax/sessions/jax/speaker/#2213">Shaun Smith</a> will hold a presentation on persistence and OSGI with eclipselink (the reference implementation of the JAVA persistence API (JPA))</a>, thus suitable persistence mechanisms for this level of modularization are likely to be close at hand.
 </li>
</ul>
<p>And if you <a href="http://it-republik.de/jaxenter/jax/sessions/?tid=1053">look at the schedule for the JAX, Europe&#8217;s most important software &#038; development conference, there have never been more OSGI topics featured</a> &#8211; at least I would doubt that.</p>
<p>In other words: OSGI will soon be so smoothly integrated with you favorite frameworks, IDE&#8217;s and API&#8217;s that using it will be a breeze &#8211; and a must, if you want to take the quality of your development process and software to the next level.</p>
]]></content:encoded>
			<wfw:commentRss>http://olafsblog.sysbsb.de/modular-development-with-osgi-about-to-be-very-very-popular-finally/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solving the eclipselink (former toplink) issue with HSQLDB</title>
		<link>http://olafsblog.sysbsb.de/eclipselink-former-toplink-issue-with-hsqldb/</link>
		<comments>http://olafsblog.sysbsb.de/eclipselink-former-toplink-issue-with-hsqldb/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 09:53:14 +0000</pubDate>
		<dc:creator>olaf</dc:creator>
				<category><![CDATA[J2EE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[eclipselink]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://olafsblog.sysbsb.de/?p=55</guid>
		<description><![CDATA[When using the great hypersonic java database (hsql) with eclipselink 1.0, i stumbled upon a schema generation (ddl generation) issue. It appears as though eclipselink generates &#8220;CREATE TABLE&#8230;&#8221; statements containing UNIQUE keywords which are incompatible with HSQLDB.
As it turned out, there already is an issue filed for the problem (240618).
The resulting exceptions look like this:

[EL [...]]]></description>
			<content:encoded><![CDATA[<p>When using the great <a href="http://hsqldb.org/">hypersonic java database (hsql)</a> with eclipselink 1.0, i stumbled upon a schema generation (ddl generation) issue. It appears as though eclipselink generates &#8220;CREATE TABLE&#8230;&#8221; statements containing <code>UNIQUE</code> keywords which are incompatible with HSQLDB.<br />
As it turned out, there already is an issue filed for the problem (<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=240618">240618</a>).</p>
<p>The resulting exceptions look like this:</p>
<p><code><br />
[EL Warning]: 2008.08.12 11:01:13.134--ServerSession(28607378)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0 (Build 1.0 - 20080707)): org.eclipse.persistence.exceptions.DatabaseException<br />
Internal Exception: java.sql.SQLException: Unexpected token: UNIQUE in statement [CREATE TABLE ... (ID INTEGER UNIQUE]<br />
Error Code: -11<br />
</code><br />
<span id="more-55"></span><br />
<a href="http://syrupsucker.blogspot.com/2008/07/hsqldb-and-toplink-uniqueness.html">Jason Drake, who reported the issue for toplink, suggests</a> modifying the <a href="http://www.eclipse.org/eclipselink/api/1.0/org/eclipse/persistence/tools/schemaframework/FieldDefinition.html">FieldDefinition</a> and <a href="http://www.eclipse.org/eclipselink/api/1.0/org/eclipse/persistence/tools/schemaframework/DefaultTableGenerator.html">DefaultTableGenerator</a>. (The error migrated from toplink into eclipselink)</p>
<p>As a simpler alternative, one might just subclass the <a href="http://www.eclipse.org/eclipselink/api/1.0/org/eclipse/persistence/platform/database/HSQLPlatform.html">HSQLPlatform</a> class and override the supportsUniqueConstraint and printFieldUnique methods. This has worked for my testsuite, which i migrated from hibernate to eclipselink.</p>
<p>Here is my subclassed HSQLPlatform implementation:</p>
<pre class="brush: java;">
package my.somepackage
/**
 * This is a workaround HSQL DB platform implementation which omits unique constraints
 * since they are not supported in the syntax that eclipselink is using.&lt;br /&gt;
 * See: &lt;a href=&quot;https://bugs.eclipse.org/bugs/show_bug.cgi?id=240618&quot;&gt;issue 240618&lt;/a&gt;.
 *
 * @author Olaf Otto
 * @see org.eclipse.persistence.platform.database.HSQLPlatform
 */
public class HsqlDbPlatform extends HSQLPlatform {
    /**
     * Workaround for  https://bugs.eclipse.org/bugs/show_bug.cgi?id=240618.
     *
     * @return &lt;code&gt;false&lt;/code&gt;.
     */
    @Override
    public boolean supportsUniqueKeyConstraints() {
        return false;
    }

    /**
     * Workaround for  https://bugs.eclipse.org/bugs/show_bug.cgi?id=240618.
     * &lt;br /&gt;
     * Does nothing.
     */
    @Override
    public void printFieldUnique(Writer writer, boolean shouldPrintFieldIdentityClause) throws IOException {
        // Do nothing.
    }
}
</pre>
<p>BTW: Eclipselink is already supported in <a href="http://www.springframework.org">Spring 2.5.2</a>. If you use spring, providing the customized database platform is a simple property change in the jpa vendor adapter:</p>
<pre class="brush: xml;">
    &lt;bean id=&quot;jpaVendorAdapter&quot; class=&quot;org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter&quot;&gt;
        &lt;property name=&quot;generateDdl&quot; value=&quot;true&quot;/&gt;
        &lt;property name=&quot;showSql&quot; value=&quot;false&quot;/&gt;
        &lt;property name=&quot;databasePlatform&quot; value=&quot;my.somepackage.HsqlDbPlatform&quot;/&gt;
    &lt;/bean&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://olafsblog.sysbsb.de/eclipselink-former-toplink-issue-with-hsqldb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why @Configurable and @Transactional don&#8217;t belong to into the same class</title>
		<link>http://olafsblog.sysbsb.de/why-configurable-and-transactional-dont-belong-to-into-the-same-class/</link>
		<comments>http://olafsblog.sysbsb.de/why-configurable-and-transactional-dont-belong-to-into-the-same-class/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 18:57:10 +0000</pubDate>
		<dc:creator>olaf</dc:creator>
				<category><![CDATA[J2EE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[System architecture]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://olafsblog.sysbsb.de/?p=35</guid>
		<description><![CDATA[When using the Spring framework, one can still benefit from dependency injection etc. even if a bean is not obtained from a bean factory by using the @Configurable annotation, f.e.:


@Configurable(value = &#34;myBean&#34;)
public class MyBean {
   ...
}

Where myBean is the bean id in the spring context.
This approach can be somewhat problematic, though, when used [...]]]></description>
			<content:encoded><![CDATA[<p>When using the <a href="http://www.springframework.org">Spring framework</a>, one can still benefit from dependency injection etc. even if a bean is not obtained from a <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/BeanFactory.html">bean factory</a> by using the <code>@Configurable</code> annotation, f.e.:<br />
<span id="more-35"></span></p>
<pre class="brush: java;">
@Configurable(value = &quot;myBean&quot;)
public class MyBean {
   ...
}
</pre>
<p>Where myBean is the bean id in the spring context.</p>
<p>This approach can be somewhat problematic, though, when used in conjunction with aspect-oriented features.<br />
Say, for example, you also want to use <a href="http://java.sun.com/developer/technicalArticles/J2EE/jpa/">JPA</a> and require a transactional behavior.</p>
<p>You would usually do the following:</p>
<pre class="brush: java;">
@Configurable(value = &quot;myBean&quot;)
public class MyBean {
   @Transactional
    public void foo() {
    ...
    }
}
</pre>
<p>This will not work, but lead to an exception like this:</p>
<p><code><br />
java.lang.IllegalStateException: Post-processor tried to replace bean instance of type [my.package.MyBean] with (proxy) object of type [my.package.MyBean$$EnhancerByCGLIB$$c029ddbf] - not supported for aspect-configured classes!<br />
</code></p>
<p>The reason is that @Configurable will ask spring to configure the current bean during constructor invokation. During configuration, a number of bean post processors will be invoked on the bean, and one of them, namely the <a href="http://www.jdocs.com/spring/2.5.2/org/springframework/aop/framework/autoproxy/InfrastructureAdvisorAutoProxyCreator.html">InfrastructureAdvisorAutoProxyCreator</a> will find the <code>@Transactional</code> annotation &#8211; which <em>advices</em> the post processor to proxy the bean in order to manage the required transaction&#8217;s context.</p>
<p>But you cannot override the expected outcome of a class instanciation with <code>new</code> with a proxy object &#8211; since it is not of the same type as the expected object!</p>
<p>Thus, <code>@Configurable</code> and <code>@Transactional</code> &#8211; together with any other advice that leads to a proxy object &#8211;  cannot coexist in your class.</p>
]]></content:encoded>
			<wfw:commentRss>http://olafsblog.sysbsb.de/why-configurable-and-transactional-dont-belong-to-into-the-same-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ClassCastException, PersistentCollection, Hibernate &amp; JPA</title>
		<link>http://olafsblog.sysbsb.de/jpa-hibernate-cannot-be-cast-to-orghibernatecollectionpersistentcollection/</link>
		<comments>http://olafsblog.sysbsb.de/jpa-hibernate-cannot-be-cast-to-orghibernatecollectionpersistentcollection/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 22:06:20 +0000</pubDate>
		<dc:creator>olaf</dc:creator>
				<category><![CDATA[J2EE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[System architecture]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://olafsblog.sysbsb.de/?p=33</guid>
		<description><![CDATA[Verwendet man Hibernate (und JPA) kann es mitunter zu recht exotischen Fehlern kommen.
Ein Beispiel, zu dem ich bei google heute nicht einen einzigen Treffer gefunden habe ist folgende Exception:

...
Caused by: javax.persistence.RollbackException: Error while commiting the transaction
        at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:71)
        at org.springframework.orm.jpa.JpaTransactionManager.doCommit(
  [...]]]></description>
			<content:encoded><![CDATA[<p>Verwendet man Hibernate (und JPA) kann es mitunter zu recht exotischen Fehlern kommen.<br />
Ein Beispiel, zu dem ich bei google heute <em>nicht einen einzigen Treffer gefunden</em> habe ist folgende Exception:</p>
<p><code><br />
...<br />
Caused by: javax.persistence.RollbackException: Error while commiting the transaction<br />
        at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:71)<br />
        at org.springframework.orm.jpa.JpaTransactionManager.doCommit(<br />
        JpaTransactionManager.java:438)<br />
        ... 55 more<br />
Caused by: <strong>java.lang.ClassCastException: java.util.HashSet<br />
        cannot be cast to org.hibernate.collection.PersistentCollection</strong><br />
        at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:34)<br />
...<br />
</code><br />
<span id="more-33"></span><br />
Das tritt dann auf, wenn man wohlmeinend die Exposition der internen Repräsentation vermeiden wollte und beispielsweise so etwas hier auf einer persistenten Collection macht:</p>
<pre class="brush: java;">
 @Entity
 public  class foo {
       private Set&lt;AnotherEntity&gt; _relatedEntites = new HashSet&lt;AnotherEntity&gt;();

     @OneToMany(cascade = {CascadeType.ALL }, fetch = FetchType.LAZY)
     @Column(name = &quot;RELATED_ENTITIES&quot;)
      public Set&lt;AnotherEntity&gt; getRelatedEntities() {
            return new HashSet&lt;AnotherEntity&gt;(_relatedEntites)
     }
 }
</pre>
<p>Das: <strong>new HashSet<AnotherEntity>(</strong>&#8230;<strong>)</strong> ist ein Fehler, da es aus der vorher erzeugten persistenten Collection wieder eine HashMap macht, die nicht persistiertbar ist.</p>
<p>Um die Manipulierbarkeit der Klasse zu vermeiden kann man stattdessen die <em>@Immutable</em>-Annotation verwenden:</p>
<pre class="brush: java;">
 @Entity
 public  class foo {
       private Set&lt;AnotherEntity&gt; _relatedEntites = new HashSet&lt;AnotherEntity&gt;();

     @OneToMany(cascade = {CascadeType.ALL }, fetch = FetchType.LAZY)
     @Column(name = &quot;RELATED_ENTITIES&quot;)
     @Immutable
      public Set&lt;AnotherEntity&gt; getRelatedEntities() {
            return _relatedEntites;
     }
 }
</pre>
<p>Dann klappt&#8217;s auch mit Hibernate.</p>
]]></content:encoded>
			<wfw:commentRss>http://olafsblog.sysbsb.de/jpa-hibernate-cannot-be-cast-to-orghibernatecollectionpersistentcollection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
