<?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"
	>
<channel>
	<title>Comments on: Spring: OpenSessionInViewInterceptor &#038; OpenSessionInViewFilter Examples</title>
	<atom:link href="http://72miles.com/blog/posts/spring-opensessioninviewinterceptor-opensessioninviewfilter-examples/feed/" rel="self" type="application/rss+xml" />
	<link>http://72miles.com/blog/posts/spring-opensessioninviewinterceptor-opensessioninviewfilter-examples/</link>
	<description>Software By Architecture, Design, and Experience</description>
	<pubDate>Fri, 05 Dec 2008 00:21:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Dan Allen</title>
		<link>http://72miles.com/blog/posts/spring-opensessioninviewinterceptor-opensessioninviewfilter-examples/#comment-38</link>
		<dc:creator>Dan Allen</dc:creator>
		<pubDate>Sat, 24 May 2008 20:21:17 +0000</pubDate>
		<guid isPermaLink="false">http://72miles.com/blog/?p=26#comment-38</guid>
		<description>You should read Spring in Seam, Part 3 (http://www.javaworld.com/javaworld/jw-05-2008/jw-05-spring-seam3.html) and chapters 8 and 9 of Seam in Action to discover why this Spring filter/interceptor is essential a huge *hack*. The persistence manager (Hibernate Session/JPA EntityManager) was designed to be extended across a series of requests, not be relegated to a single request or worse service layer call. LazyInitializationExceptions happen because the persistence manager is scoped incorrectly.&lt;div class="comment-remix-meta"&gt;&lt;a href="#" class="replyto" onclick="replyto('38','Dan Allen'); return false;"&gt;Reply&lt;/a&gt;  - &lt;a href="#" class="quote" onclick="quote('38','Dan Allen','You should read Spring in Seam, Part 3 (http:\/\/www.javaworld.com\/javaworld\/jw-05-2008\/jw-05-spring-seam3.html) and chapters 8 and 9 of Seam in Action to discover why this Spring filter\/interceptor is essential a huge *hack*. The persistence manager (Hibernate Session\/JPA EntityManager) was designed to be extended across a series of requests, not be relegated to a single request or worse service layer call. LazyInitializationExceptions happen because the persistence manager is scoped incorrectly.'); return false;"&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>You should read Spring in Seam, Part 3 (http://www.javaworld.com/javaworld/jw-05-2008/jw-05-spring-seam3.html) and chapters 8 and 9 of Seam in Action to discover why this Spring filter/interceptor is essential a huge *hack*. The persistence manager (Hibernate Session/JPA EntityManager) was designed to be extended across a series of requests, not be relegated to a single request or worse service layer call. LazyInitializationExceptions happen because the persistence manager is scoped incorrectly.
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('38','Dan Allen'); return false;">Reply</a>  - <a href="#" class="quote" onclick="quote('38','Dan Allen','You should read Spring in Seam, Part 3 (http:\/\/www.javaworld.com\/javaworld\/jw-05-2008\/jw-05-spring-seam3.html) and chapters 8 and 9 of Seam in Action to discover why this Spring filter\/interceptor is essential a huge *hack*. The persistence manager (Hibernate Session\/JPA EntityManager) was designed to be extended across a series of requests, not be relegated to a single request or worse service layer call. LazyInitializationExceptions happen because the persistence manager is scoped incorrectly.'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: delta one</title>
		<link>http://72miles.com/blog/posts/spring-opensessioninviewinterceptor-opensessioninviewfilter-examples/#comment-37</link>
		<dc:creator>delta one</dc:creator>
		<pubDate>Sat, 24 May 2008 19:53:07 +0000</pubDate>
		<guid isPermaLink="false">http://72miles.com/blog/?p=26#comment-37</guid>
		<description>Excellent example!&lt;div class="comment-remix-meta"&gt;&lt;a href="#" class="replyto" onclick="replyto('37','delta one'); return false;"&gt;Reply&lt;/a&gt;  - &lt;a href="#" class="quote" onclick="quote('37','delta one','Excellent example!'); return false;"&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>Excellent example!
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('37','delta one'); return false;">Reply</a>  - <a href="#" class="quote" onclick="quote('37','delta one','Excellent example!'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: weggyboy</title>
		<link>http://72miles.com/blog/posts/spring-opensessioninviewinterceptor-opensessioninviewfilter-examples/#comment-36</link>
		<dc:creator>weggyboy</dc:creator>
		<pubDate>Sat, 24 May 2008 19:52:35 +0000</pubDate>
		<guid isPermaLink="false">http://72miles.com/blog/?p=26#comment-36</guid>
		<description>Nice Post, but it only works for views, doesnÃ‚Â´t it?

I was trying to change some entries after the proposed changes and found out, that the write operations are not allowed with the default session setting for the openViewInSession filter.
After searching for a solution IÃ‚Â´ve found that:

import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;
import org.hibernate.*;
import org.springframework.dao.*;

public class SessionFilter extends OpenSessionInViewFilter {
/*
* The default mode is FlushMode.NEVER
*
* @see org.springframework.orm.hibernate.support.OpenSessionInViewFilter#getSession(net.sf.hibernate.SessionFactory)
*/
protected Session getSession(SessionFactory sessionFactory)
throws DataAccessResourceFailureException {
Session session = super.getSession(sessionFactory);
session.setFlushMode(FlushMode.COMMIT);
return session;
}

/**
* we do an explicit flush here just in case we do not have an automated flush
*/
protected void closeSession(Session session, SessionFactory factory) {
session.flush();
super.closeSession(session, factory);
}
}

Now it works as wished!&lt;div class="comment-remix-meta"&gt;&lt;a href="#" class="replyto" onclick="replyto('36','weggyboy'); return false;"&gt;Reply&lt;/a&gt;  - &lt;a href="#" class="quote" onclick="quote('36','weggyboy','Nice Post, but it only works for views, doesn&#195;‚&#194;&#180;t it?\r\n\r\nI was trying to change some entries after the proposed changes and found out, that the write operations are not allowed with the default session setting for the openViewInSession filter.\r\nAfter searching for a solution I&#195;‚&#194;&#180;ve found that:\r\n\r\nimport org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;\r\nimport org.hibernate.*;\r\nimport org.springframework.dao.*;\r\n\r\npublic class SessionFilter extends OpenSessionInViewFilter {\r\n\/*\r\n* The default mode is FlushMode.NEVER\r\n*\r\n* @see org.springframework.orm.hibernate.support.OpenSessionInViewFilter#getSession(net.sf.hibernate.SessionFactory)\r\n*\/\r\nprotected Session getSession(SessionFactory sessionFactory)\r\nthrows DataAccessResourceFailureException {\r\nSession session = super.getSession(sessionFactory);\r\nsession.setFlushMode(FlushMode.COMMIT);\r\nreturn session;\r\n}\r\n\r\n\/**\r\n* we do an explicit flush here just in case we do not have an automated flush\r\n*\/\r\nprotected void closeSession(Session session, SessionFactory factory) {\r\nsession.flush();\r\nsuper.closeSession(session, factory);\r\n}\r\n}\r\n\r\nNow it works as wished!'); return false;"&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>Nice Post, but it only works for views, doesnÃ‚Â´t it?</p>
<p>I was trying to change some entries after the proposed changes and found out, that the write operations are not allowed with the default session setting for the openViewInSession filter.<br />
After searching for a solution IÃ‚Â´ve found that:</p>
<p>import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;<br />
import org.hibernate.*;<br />
import org.springframework.dao.*;</p>
<p>public class SessionFilter extends OpenSessionInViewFilter {<br />
/*<br />
* The default mode is FlushMode.NEVER<br />
*<br />
* @see org.springframework.orm.hibernate.support.OpenSessionInViewFilter#getSession(net.sf.hibernate.SessionFactory)<br />
*/<br />
protected Session getSession(SessionFactory sessionFactory)<br />
throws DataAccessResourceFailureException {<br />
Session session = super.getSession(sessionFactory);<br />
session.setFlushMode(FlushMode.COMMIT);<br />
return session;<br />
}</p>
<p>/**<br />
* we do an explicit flush here just in case we do not have an automated flush<br />
*/<br />
protected void closeSession(Session session, SessionFactory factory) {<br />
session.flush();<br />
super.closeSession(session, factory);<br />
}<br />
}</p>
<p>Now it works as wished!
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('36','weggyboy'); return false;">Reply</a>  - <a href="#" class="quote" onclick="quote('36','weggyboy','Nice Post, but it only works for views, doesn&Atilde;‚&Acirc;&acute;t it?\r\n\r\nI was trying to change some entries after the proposed changes and found out, that the write operations are not allowed with the default session setting for the openViewInSession filter.\r\nAfter searching for a solution I&Atilde;‚&Acirc;&acute;ve found that:\r\n\r\nimport org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;\r\nimport org.hibernate.*;\r\nimport org.springframework.dao.*;\r\n\r\npublic class SessionFilter extends OpenSessionInViewFilter {\r\n\/*\r\n* The default mode is FlushMode.NEVER\r\n*\r\n* @see org.springframework.orm.hibernate.support.OpenSessionInViewFilter#getSession(net.sf.hibernate.SessionFactory)\r\n*\/\r\nprotected Session getSession(SessionFactory sessionFactory)\r\nthrows DataAccessResourceFailureException {\r\nSession session = super.getSession(sessionFactory);\r\nsession.setFlushMode(FlushMode.COMMIT);\r\nreturn session;\r\n}\r\n\r\n\/**\r\n* we do an explicit flush here just in case we do not have an automated flush\r\n*\/\r\nprotected void closeSession(Session session, SessionFactory factory) {\r\nsession.flush();\r\nsuper.closeSession(session, factory);\r\n}\r\n}\r\n\r\nNow it works as wished!'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://72miles.com/blog/posts/spring-opensessioninviewinterceptor-opensessioninviewfilter-examples/#comment-35</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Sat, 24 May 2008 19:51:53 +0000</pubDate>
		<guid isPermaLink="false">http://72miles.com/blog/?p=26#comment-35</guid>
		<description>For those of you using the Persistence API, there is also an EntityManager version:

org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor

Thanks for your example, Chris

PS I would put an example - but seems the comments box does not allow it :(&lt;div class="comment-remix-meta"&gt;&lt;a href="#" class="replyto" onclick="replyto('35','Anonymous'); return false;"&gt;Reply&lt;/a&gt;  - &lt;a href="#" class="quote" onclick="quote('35','Anonymous','For those of you using the Persistence API, there is also an EntityManager version:\r\n\r\norg.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor\r\n\r\nThanks for your example, Chris\r\n\r\nPS I would put an example - but seems the comments box does not allow it :('); return false;"&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>For those of you using the Persistence API, there is also an EntityManager version:</p>
<p>org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor</p>
<p>Thanks for your example, Chris</p>
<p>PS I would put an example - but seems the comments box does not allow it <img src='http://72miles.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('35','Anonymous'); return false;">Reply</a>  - <a href="#" class="quote" onclick="quote('35','Anonymous','For those of you using the Persistence API, there is also an EntityManager version:\r\n\r\norg.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor\r\n\r\nThanks for your example, Chris\r\n\r\nPS I would put an example - but seems the comments box does not allow it :('); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: cookie</title>
		<link>http://72miles.com/blog/posts/spring-opensessioninviewinterceptor-opensessioninviewfilter-examples/#comment-34</link>
		<dc:creator>cookie</dc:creator>
		<pubDate>Sat, 24 May 2008 19:51:23 +0000</pubDate>
		<guid isPermaLink="false">http://72miles.com/blog/?p=26#comment-34</guid>
		<description>Hi Mike,
Kudos on the great explanations and examples.

I am a newbie to Spring (as well as Java :P). I have a question regarding OpenSessionInViewInterceptor/ Filter.

I have a Spring app that only selective controllers requires open sessions. Can I selectively "hook-up" the interceptor to those controllers?

Thanks a lot.

YS&lt;div class="comment-remix-meta"&gt;&lt;a href="#" class="replyto" onclick="replyto('34','cookie'); return false;"&gt;Reply&lt;/a&gt;  - &lt;a href="#" class="quote" onclick="quote('34','cookie','Hi Mike,\r\nKudos on the great explanations and examples.\r\n\r\nI am a newbie to Spring (as well as Java :P). I have a question regarding OpenSessionInViewInterceptor\/ Filter.\r\n\r\nI have a Spring app that only selective controllers requires open sessions. Can I selectively \&#34;hook-up\&#34; the interceptor to those controllers?\r\n\r\nThanks a lot.\r\n\r\nYS'); return false;"&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>Hi Mike,<br />
Kudos on the great explanations and examples.</p>
<p>I am a newbie to Spring (as well as Java :P). I have a question regarding OpenSessionInViewInterceptor/ Filter.</p>
<p>I have a Spring app that only selective controllers requires open sessions. Can I selectively &#8220;hook-up&#8221; the interceptor to those controllers?</p>
<p>Thanks a lot.</p>
<p>YS
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('34','cookie'); return false;">Reply</a>  - <a href="#" class="quote" onclick="quote('34','cookie','Hi Mike,\r\nKudos on the great explanations and examples.\r\n\r\nI am a newbie to Spring (as well as Java :P). I have a question regarding OpenSessionInViewInterceptor\/ Filter.\r\n\r\nI have a Spring app that only selective controllers requires open sessions. Can I selectively \&quot;hook-up\&quot; the interceptor to those controllers?\r\n\r\nThanks a lot.\r\n\r\nYS'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://72miles.com/blog/posts/spring-opensessioninviewinterceptor-opensessioninviewfilter-examples/#comment-33</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Sat, 24 May 2008 19:50:33 +0000</pubDate>
		<guid isPermaLink="false">http://72miles.com/blog/?p=26#comment-33</guid>
		<description>Too true. I hate going to software blogs and seeing nothing but paragraph after paragraph. I want to see code that I can copy and paste, that has comments in it so that I can follow it.

Glad I could help. Cheers.&lt;div class="comment-remix-meta"&gt;&lt;a href="#" class="replyto" onclick="replyto('33','Mike'); return false;"&gt;Reply&lt;/a&gt;  - &lt;a href="#" class="quote" onclick="quote('33','Mike','Too true. I hate going to software blogs and seeing nothing but paragraph after paragraph. I want to see code that I can copy and paste, that has comments in it so that I can follow it.\r\n\r\nGlad I could help. Cheers.'); return false;"&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>Too true. I hate going to software blogs and seeing nothing but paragraph after paragraph. I want to see code that I can copy and paste, that has comments in it so that I can follow it.</p>
<p>Glad I could help. Cheers.
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('33','Mike'); return false;">Reply</a>  - <a href="#" class="quote" onclick="quote('33','Mike','Too true. I hate going to software blogs and seeing nothing but paragraph after paragraph. I want to see code that I can copy and paste, that has comments in it so that I can follow it.\r\n\r\nGlad I could help. Cheers.'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://72miles.com/blog/posts/spring-opensessioninviewinterceptor-opensessioninviewfilter-examples/#comment-32</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Sat, 24 May 2008 19:49:40 +0000</pubDate>
		<guid isPermaLink="false">http://72miles.com/blog/?p=26#comment-32</guid>
		<description>thanks a lot! code is better than 1000 blog post! :D&lt;div class="comment-remix-meta"&gt;&lt;a href="#" class="replyto" onclick="replyto('32','Anonymous'); return false;"&gt;Reply&lt;/a&gt;  - &lt;a href="#" class="quote" onclick="quote('32','Anonymous','thanks a lot! code is better than 1000 blog post! :D'); return false;"&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>thanks a lot! code is better than 1000 blog post! <img src='http://72miles.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('32','Anonymous'); return false;">Reply</a>  - <a href="#" class="quote" onclick="quote('32','Anonymous','thanks a lot! code is better than 1000 blog post! :D'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://72miles.com/blog/posts/spring-opensessioninviewinterceptor-opensessioninviewfilter-examples/#comment-31</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Sat, 24 May 2008 19:49:20 +0000</pubDate>
		<guid isPermaLink="false">http://72miles.com/blog/?p=26#comment-31</guid>
		<description>Thanks.&lt;div class="comment-remix-meta"&gt;&lt;a href="#" class="replyto" onclick="replyto('31','Anonymous'); return false;"&gt;Reply&lt;/a&gt;  - &lt;a href="#" class="quote" onclick="quote('31','Anonymous','Thanks.'); return false;"&gt;Quote&lt;/a&gt;&lt;/div&gt;</description>
		<content:encoded><![CDATA[<p>Thanks.
<div class="comment-remix-meta"><a href="#" class="replyto" onclick="replyto('31','Anonymous'); return false;">Reply</a>  - <a href="#" class="quote" onclick="quote('31','Anonymous','Thanks.'); return false;">Quote</a></div>
]]></content:encoded>
	</item>
</channel>
</rss>
