<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Building a smart EntityModel</title>
	<atom:link href="http://wicketinaction.com/2008/09/building-a-smart-entitymodel/feed/" rel="self" type="application/rss+xml" />
	<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/</link>
	<description>A comprehensive guide for Java developers building Wicket-based web applications</description>
	<lastBuildDate>Tue, 22 Nov 2011 11:29:42 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: ivaynberg</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/comment-page-1/#comment-563</link>
		<dc:creator>ivaynberg</dc:creator>
		<pubDate>Thu, 30 Jul 2009 17:02:55 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-563</guid>
		<description>@Ian: Absolutely. Here is a bit cleaner code if you are working with hibernate:

&lt;code&gt;public static &lt;T&gt; T unproxy(T entity)
    {
        if (entity instanceof HibernateProxy)
        {
            entity = (T)((HibernateProxy)entity).getHibernateLazyInitializer().getImplementation();
        }
        return entity;
    }&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>@Ian: Absolutely. Here is a bit cleaner code if you are working with hibernate:</p>
<p><code>public static <t> T unproxy(T entity)<br />
    {<br />
        if (entity instanceof HibernateProxy)<br />
        {<br />
            entity = (T)((HibernateProxy)entity).getHibernateLazyInitializer().getImplementation();<br />
        }<br />
        return entity;<br />
    }</t></code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Iain Reddick</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/comment-page-1/#comment-552</link>
		<dc:creator>Iain Reddick</dc:creator>
		<pubDate>Fri, 24 Jul 2009 11:40:28 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-552</guid>
		<description>There is another consideration with AbstractEntityModel.

If you are working with hibernate-persisted entities, or objects that may be proxied in some other way, the object passed in to the constructor may be a proxy (i.e. it is of a proxy class, not the OR-mapped class). This obviously causes a problem when you come to regenerate the object (in hibernate this will give an unmapped entity exception).

The solution is to check if the class is a proxy class before attempting to load the entity. If it is a proxy, then retrieve the mapped class and use that to load.

e.g. for CGLIB proxies:

Class entityClass = clazz;
if ( net.sf.cglib.proxy.Enhancer.isEnhanced(entityClass) ) {
    // is a proxy
    entityClass = clazz.getSuperclass();
}</description>
		<content:encoded><![CDATA[<p>There is another consideration with AbstractEntityModel.</p>
<p>If you are working with hibernate-persisted entities, or objects that may be proxied in some other way, the object passed in to the constructor may be a proxy (i.e. it is of a proxy class, not the OR-mapped class). This obviously causes a problem when you come to regenerate the object (in hibernate this will give an unmapped entity exception).</p>
<p>The solution is to check if the class is a proxy class before attempting to load the entity. If it is a proxy, then retrieve the mapped class and use that to load.</p>
<p>e.g. for CGLIB proxies:</p>
<p>Class entityClass = clazz;<br />
if ( net.sf.cglib.proxy.Enhancer.isEnhanced(entityClass) ) {<br />
    // is a proxy<br />
    entityClass = clazz.getSuperclass();<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ReinoutS</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/comment-page-1/#comment-501</link>
		<dc:creator>ReinoutS</dc:creator>
		<pubDate>Thu, 04 Jun 2009 15:08:28 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-501</guid>
		<description>With the example EntityModel code, I&#039;m getting a compile error because load() doesn&#039;t return a T but instead, an Identifiable.

Am I missing something?</description>
		<content:encoded><![CDATA[<p>With the example EntityModel code, I&#8217;m getting a compile error because load() doesn&#8217;t return a T but instead, an Identifiable.</p>
<p>Am I missing something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sams</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/comment-page-1/#comment-495</link>
		<dc:creator>Sams</dc:creator>
		<pubDate>Fri, 15 May 2009 12:10:36 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-495</guid>
		<description>Update: I think I&#039;ve solved this by using a custom RequestCycleProcessor and doing the commit in the respond method. Working well so far.</description>
		<content:encoded><![CDATA[<p>Update: I think I&#8217;ve solved this by using a custom RequestCycleProcessor and doing the commit in the respond method. Working well so far.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sams</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/comment-page-1/#comment-494</link>
		<dc:creator>Sams</dc:creator>
		<pubDate>Wed, 13 May 2009 22:24:51 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-494</guid>
		<description>I&#039;ve tried the approach of commiting the transaction in onEndRequest in the request cycle. The question is what happens if the commit fails - because the response has already been sent at that stage. Depending on your database and configuration, commits can fail due to IO failures, uniqueness constraint failures, collisions, etc. I would still like to do one commit per request since this seems ideal for DB4O, but am not sure where to put the commit.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve tried the approach of commiting the transaction in onEndRequest in the request cycle. The question is what happens if the commit fails &#8211; because the response has already been sent at that stage. Depending on your database and configuration, commits can fail due to IO failures, uniqueness constraint failures, collisions, etc. I would still like to do one commit per request since this seems ideal for DB4O, but am not sure where to put the commit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Seam / JSF vs Wicket: performance comparison &#171; Incremental Operations</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/comment-page-1/#comment-376</link>
		<dc:creator>Seam / JSF vs Wicket: performance comparison &#171; Incremental Operations</dc:creator>
		<pubDate>Wed, 14 Jan 2009 15:41:43 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-376</guid>
		<description>[...] Implemented what I hope is the exact equivalent of the above using only Wicket and JPA, also Maven-ized and Jetty-fied. Decided to also experiment with some of the ideas in this blog post. [...]</description>
		<content:encoded><![CDATA[<p>[...] Implemented what I hope is the exact equivalent of the above using only Wicket and JPA, also Maven-ized and Jetty-fied. Decided to also experiment with some of the ideas in this blog post. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ivaynberg</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/comment-page-1/#comment-294</link>
		<dc:creator>ivaynberg</dc:creator>
		<pubDate>Mon, 15 Dec 2008 18:49:09 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-294</guid>
		<description>@Paul: I had to do a lot of refactoring in 1.4 to get this working correctly. Unfortunately I cannot port this back to 1.3 because it has production apps running on it that might depend on the functionality this changed.

It is pretty easy to set up a single-transaction-per-request pattern in wicket. It is not as granular as a transaction for the form submit, but it should still work.

&lt;pre lang=&quot;java&quot;&gt;
public class WicketRequestCycle extends WebRequestCycle
{
    private TransactionStatus txn;

    @Dependency
    private PlatformTransactionManager txm;

    public WicketRequestCycle(WebApplication application, WebRequest request, Response response)
    {
        super(application, request, response);
    }

    @Override
    protected void onBeginRequest()
    {
        txn = txm.getTransaction(new DefaultTransactionDefinition());
        super.onBeginRequest();
    }

    @Override
    protected void onEndRequest()
    {
        super.onEndRequest();
        if (txn != null)
        {
            txm.commit(txn);
            txn = null;
        }
    }

    @Override
    public Page onRuntimeException(Page page, RuntimeException e)
    {
        if (txn != null)
        {
            txm.rollback(txn);
            txn = null;
        }
        return super.onRuntimeException(page, e);
    }
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>@Paul: I had to do a lot of refactoring in 1.4 to get this working correctly. Unfortunately I cannot port this back to 1.3 because it has production apps running on it that might depend on the functionality this changed.</p>
<p>It is pretty easy to set up a single-transaction-per-request pattern in wicket. It is not as granular as a transaction for the form submit, but it should still work.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WicketRequestCycle <span style="color: #000000; font-weight: bold;">extends</span> WebRequestCycle
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> TransactionStatus txn<span style="color: #339933;">;</span>
&nbsp;
    @Dependency
    <span style="color: #000000; font-weight: bold;">private</span> PlatformTransactionManager txm<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> WicketRequestCycle<span style="color: #009900;">&#40;</span>WebApplication application, WebRequest request, Response response<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>application, request, response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onBeginRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        txn <span style="color: #339933;">=</span> txm.<span style="color: #006633;">getTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> DefaultTransactionDefinition<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onBeginRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onEndRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onEndRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>txn <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            txm.<span style="color: #006633;">commit</span><span style="color: #009900;">&#40;</span>txn<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            txn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> Page onRuntimeException<span style="color: #009900;">&#40;</span>Page page, <span style="color: #003399;">RuntimeException</span> e<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>txn <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            txm.<span style="color: #006633;">rollback</span><span style="color: #009900;">&#40;</span>txn<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            txn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onRuntimeException</span><span style="color: #009900;">&#40;</span>page, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Mogren</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/comment-page-1/#comment-293</link>
		<dc:creator>Paul Mogren</dc:creator>
		<pubDate>Mon, 15 Dec 2008 16:42:29 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-293</guid>
		<description>@Igor 
In reference to comment #18, 
I&#039;m trying to find a way to achieve this in Wicket 1.3, and having a hard time. It appears that onSubmit() is not called within form.process(), and a lot of the methods I might try to override for this are declared final. Can you (or anyone) suggest where I can begin and end the transaction? THanks</description>
		<content:encoded><![CDATA[<p>@Igor<br />
In reference to comment #18,<br />
I&#8217;m trying to find a way to achieve this in Wicket 1.3, and having a hard time. It appears that onSubmit() is not called within form.process(), and a lot of the methods I might try to override for this are declared final. Can you (or anyone) suggest where I can begin and end the transaction? THanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Persistenz für den Feedreader - rattlab.net</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/comment-page-1/#comment-108</link>
		<dc:creator>Persistenz für den Feedreader - rattlab.net</dc:creator>
		<pubDate>Tue, 28 Oct 2008 20:01:43 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-108</guid>
		<description>[...] Das NewsModel ist nicht von LoadableDetachableModel abgeleitet, da wir keinen schreibenden Zugriff auf das zu speichernde Objekt hätten, sondern dieses immer über load() geladen werden müsste. Dennoch ist die Model-Klasse recht einfach und übersichtlich. Es speichert die ID und die News selbst, beim Speichern in der Session wird die News aber nicht serialisiert. Werden die Daten wieder aus der Session geholt (z.B. durch ein Neu Laden der Seite), so wird die News anhand der ID erneut aus der Datenbank geladen. Eine allgemein gehaltenere Version eines solchen Models beschreibt Igor Vaynberg, einer der Wicket-Mitentwickler, im Blogeintrag &#8220;Building a smart EntityModel&#8221;. [...]</description>
		<content:encoded><![CDATA[<p>[...] Das NewsModel ist nicht von LoadableDetachableModel abgeleitet, da wir keinen schreibenden Zugriff auf das zu speichernde Objekt hätten, sondern dieses immer über load() geladen werden müsste. Dennoch ist die Model-Klasse recht einfach und übersichtlich. Es speichert die ID und die News selbst, beim Speichern in der Session wird die News aber nicht serialisiert. Werden die Daten wieder aus der Session geholt (z.B. durch ein Neu Laden der Seite), so wird die News anhand der ID erneut aus der Datenbank geladen. Eine allgemein gehaltenere Version eines solchen Models beschreibt Igor Vaynberg, einer der Wicket-Mitentwickler, im Blogeintrag &#8220;Building a smart EntityModel&#8221;. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jörn Zaefferer</title>
		<link>http://wicketinaction.com/2008/09/building-a-smart-entitymodel/comment-page-1/#comment-27</link>
		<dc:creator>Jörn Zaefferer</dc:creator>
		<pubDate>Mon, 06 Oct 2008 13:33:29 +0000</pubDate>
		<guid isPermaLink="false">http://wicketinaction.com/?p=84#comment-27</guid>
		<description>Okay, that makes sense. Thanks for clarifying.</description>
		<content:encoded><![CDATA[<p>Okay, that makes sense. Thanks for clarifying.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

