<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Mind blockers: weird bugs</title>
	<atom:link href="http://blockers.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blockers.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Thu, 04 Jun 2009 14:17:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blockers.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Mind blockers: weird bugs</title>
		<link>http://blockers.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blockers.wordpress.com/osd.xml" title="Mind blockers: weird bugs" />
	<atom:link rel='hub' href='http://blockers.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Using proxied SessionFactory in Spring 2.5.x application</title>
		<link>http://blockers.wordpress.com/2009/06/04/using-proxied-sessionfactory-in-spring-2-5-x-application/</link>
		<comments>http://blockers.wordpress.com/2009/06/04/using-proxied-sessionfactory-in-spring-2-5-x-application/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 14:17:44 +0000</pubDate>
		<dc:creator>blockers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[Session closed]]></category>
		<category><![CDATA[SessionFactory]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blockers.wordpress.com/?p=10</guid>
		<description><![CDATA[Suppose you want to use a proxied SessionFactory in your Spring + Hibernate web application, which uses AOP-defined transactions. The most straight forward way to go is to feed Spring with the proxied version of the SessionFactory, instead of the normal bean. We tried to do the same thing in one of our projects, but [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blockers.wordpress.com&amp;blog=7192763&amp;post=10&amp;subd=blockers&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Suppose you want to use a proxied SessionFactory in your Spring + Hibernate web application, which uses AOP-defined transactions. The most straight forward way to go is to feed Spring with the proxied version of the SessionFactory, instead of the normal bean.</p>
<p>We tried to do the same thing in one of our projects, but it didn&#8217;t work on all pages (strange enough, it worked on some pages!). Sometimes, an exception saying &#8220;Session is closed&#8221; was thrown, while trying to execute a method in a transaction.</p>
<p>We started to research the problem using our dear friend, Google.</p>
<p>- asking on the Hibernate forum yielded no better way of doing it: <a href="https://forum.hibernate.org/viewtopic.php?f=1&amp;t=996324&amp;view=previous" target="_blank">https://forum.hibernate.org/viewtopic.php?f=1&amp;t=996324&amp;view=previous</a> (we actually wanted to measure the execution time of each query, and we know about the approach with Hibernate Statistics, but we want more detailed statistics; resetting the statistics after each query is not an option)</p>
<p>- nobody from the Spring forums was interested: <a href="http://forum.springsource.org/showthread.php?t=70086" target="_blank">http://forum.springsource.org/showthread.php?t=70086</a></p>
<p>- we found two related tickets in Spring&#8217;s JIRA: <a href="http://jira.springframework.org/browse/SPR-5033" target="_blank">http://jira.springframework.org/browse/SPR-5033</a> and <a href="http://jira.springframework.org/browse/SPR-3367" target="_blank">http://jira.springframework.org/browse/SPR-3367</a></p>
<p>After endless hours of debugging and studying the Spring source code, we arrived to the following conclusion:</p>
<p>The problem was that our proxied Session objects weren&#8217;t returning the correct hashCode(). We were using JDK 1.3 proxies implementing Session interface to proxy them, and delegating calls to a real &#8220;Session&#8221; object. According to the proxy documentation <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/reflect/Proxy.html" target="_blank">here</a>, &#8220;equals&#8221;, &#8220;hashCode&#8221; and &#8220;toString&#8221; methods of a proxied object are also routed through the proxy.</p>
<p>The solution that worked for us was found in the HibernateTemplate.java file, in the Spring source code. It seems that they are creating Session proxies as well in there, and we shamelessly (:P) copied their method:</p>
<p>1) Create proxies using this method:</p>
<p>// CreateProxiedSession.java</p>
<p>protected Session createSessionProxy(Session session) {<br />
     Class[] sessionIfcs = null;<br />
     Class mainIfc = (session instanceof org.hibernate.classic.Session ?<br />
 org.hibernate.classic.Session.class : Session.class);<br />
     if (session instanceof EventSource) {<br />
         sessionIfcs = new Class[] {mainIfc, EventSource.class};<br />
     } else if (session instanceof SessionImplementor) {<br />
         sessionIfcs = new Class[] {mainIfc, SessionImplementor.class};<br />
     } else {<br />
         sessionIfcs = new Class[] {mainIfc};<br />
     }</p>
<p>     return (Session) Proxy.newProxyInstance(session.getClass().getClassLoader(), sessionIfcs, new SessionInvocationHandler(session, statistics));<br />
 }</p>
<p>2) Make sure that the correct hashCode() is returned from the proxied Session:</p>
<p>public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {</p>
<p>    Object result = null;</p>
<p>    if (m.getName().equals(&#8220;equals&#8221;)) {<br />
    // Only consider equal when proxies are identical.<br />
        return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);<br />
    } else if (m.getName().equals(&#8220;hashCode&#8221;)) {<br />
    // Use hashCode of Session proxy.<br />
        return new Integer(System.identityHashCode(proxy));<br />
    }</p>
<p>    // Invoke the method on the proxied session, and do whatever proxying you want</p>
<p>    // &#8230;.</p>
<p>}</p>
<p>We&#8217;ll be investigating the root source once we have enough time.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blockers.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blockers.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blockers.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blockers.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blockers.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blockers.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blockers.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blockers.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blockers.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blockers.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blockers.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blockers.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blockers.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blockers.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blockers.wordpress.com&amp;blog=7192763&amp;post=10&amp;subd=blockers&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blockers.wordpress.com/2009/06/04/using-proxied-sessionfactory-in-spring-2-5-x-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/760918d2ec8d126bc0593548de298225?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">blockers</media:title>
		</media:content>
	</item>
		<item>
		<title>No matching factory method found, Spring Framework</title>
		<link>http://blockers.wordpress.com/2009/04/07/no-matching-factory-method-found-spring-framework/</link>
		<comments>http://blockers.wordpress.com/2009/04/07/no-matching-factory-method-found-spring-framework/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 11:17:04 +0000</pubDate>
		<dc:creator>blockers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[BeanCreationException]]></category>
		<category><![CDATA[spring framework]]></category>

		<guid isPermaLink="false">http://blockers.wordpress.com/?p=8</guid>
		<description><![CDATA[Say you’re trying to set-up a bean in Spring. And that you want it to be constructed by using a non-static factory method, of another bean. Normally, you do it like this: &#60;bean id=”factory” class=”com.foo.Factory”/&#62; &#60;bean id=”createdByFactory” factory-bean=”factory” factory-method=”createInstance”/&#62; (note that you can name the method in the factory whatever you want). And you keep [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blockers.wordpress.com&amp;blog=7192763&amp;post=8&amp;subd=blockers&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="snap_preview">
<p>Say you’re trying to set-up a bean in Spring. And that you want it to be constructed by using a non-static factory method, of another bean. Normally, you do it like this:</p>
<p>&lt;bean id=”factory” class=”com.foo.Factory”/&gt;</p>
<p>&lt;bean id=”createdByFactory” factory-bean=”factory” factory-method=”createInstance”/&gt;</p>
<p>(note that you can name the method in the factory whatever you want). And you keep getting this weird error, that no matching factory method. What the heck? You&#8217;ve just triple-checked your code, and the method <strong>is there</strong>.</p>
<p>This is nothing but a classical case of &#8220;non-related error message that keeps you debugging for hours&#8221;. The secret lies in the class org.springframework.beans.factory.support.ConstructorResolver, method instantiateUsingFactoryMethod. Basically, because of all the coolness of IOC (Inversion of Control), Spring can’t figure out which of the methods named createInstance (or whatever you set your factory-method to) is the one to go. Because, you know, there might be a few of them. Thus, it goes about using trial &amp; error.</p>
<p>But … wait! That means that if I have a stupid bug in my factory method, createInstance() that crashes it whenever Spring calls it, that will also be a “no matching factory method”, at least from Spring’s point of view.</p>
<p>Activating logging for “org.springframework” at “TRACE” level didn’t help at all. Hey Spring guys, if you hear me, please insert some logging statements in yer class. Thanks, mates!</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blockers.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blockers.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blockers.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blockers.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blockers.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blockers.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blockers.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blockers.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blockers.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blockers.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blockers.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blockers.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blockers.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blockers.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blockers.wordpress.com&amp;blog=7192763&amp;post=8&amp;subd=blockers&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blockers.wordpress.com/2009/04/07/no-matching-factory-method-found-spring-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/760918d2ec8d126bc0593548de298225?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">blockers</media:title>
		</media:content>
	</item>
		<item>
		<title>Hibernate, ClassCastException, java.lang.Long</title>
		<link>http://blockers.wordpress.com/2009/04/01/hibernate-classcastexception-javalanglong/</link>
		<comments>http://blockers.wordpress.com/2009/04/01/hibernate-classcastexception-javalanglong/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 13:35:46 +0000</pubDate>
		<dc:creator>blockers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ClassCastException]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java.lang.Long]]></category>

		<guid isPermaLink="false">http://blockers.wordpress.com/?p=4</guid>
		<description><![CDATA[Whenever migrating to newer versions of Hibernate, make sure your app can handle it Yesterday, while trying to deploy an app to JBoss 4.2.2, I was getting screenloads of exceptions resembling this post&#8217;s title. Well, they&#8217;re because when your app was written, Hibernate used to return Integer as the result type for HQL operations such [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blockers.wordpress.com&amp;blog=7192763&amp;post=4&amp;subd=blockers&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Whenever migrating to newer versions of Hibernate, make sure your app can handle it <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Yesterday, while trying to deploy an app to JBoss 4.2.2, I was getting screenloads of exceptions resembling this post&#8217;s title. Well, they&#8217;re because when your app was written, Hibernate used to return Integer as the result type for HQL operations such as sum(), count() and avg(). But Santa brought a big present along with the new versions: no more Integer for you, Long is the name of the game from now on.</p>
<p>If you&#8217;re using Spring&#8217;s hibernateTemplate to integrate with Hibernate, there&#8217;s a simple solution to this. Override Spring&#8217;s LocalSessionFactoryBean and implement the method postProcessConfiguration.</p>
<p>The light at the end of the tunnel (config is the object passed to you by the method postProcessConfiguration):<br />
config.addSqlFunction( &#8220;count&#8221;, new ClassicCountFunction());<br />
config.addSqlFunction( &#8220;avg&#8221;, new ClassicAvgFunction());<br />
config.addSqlFunction( &#8220;sum&#8221;, new ClassicSumFunction());</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blockers.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blockers.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blockers.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blockers.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blockers.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blockers.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blockers.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blockers.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blockers.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blockers.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blockers.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blockers.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blockers.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blockers.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blockers.wordpress.com&amp;blog=7192763&amp;post=4&amp;subd=blockers&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blockers.wordpress.com/2009/04/01/hibernate-classcastexception-javalanglong/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/760918d2ec8d126bc0593548de298225?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">blockers</media:title>
		</media:content>
	</item>
		<item>
		<title>Motivation</title>
		<link>http://blockers.wordpress.com/2009/04/01/motivation/</link>
		<comments>http://blockers.wordpress.com/2009/04/01/motivation/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 13:26:24 +0000</pubDate>
		<dc:creator>blockers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blockers.wordpress.com/2009/04/01/motivation/</guid>
		<description><![CDATA[We&#8217;re a small development team with 3 members, working mostly on J2EE applications (but not only). We&#8217;re not afraid to get our hands dirty, and go to the darkest places in order to remove those annoying bugs<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blockers.wordpress.com&amp;blog=7192763&amp;post=3&amp;subd=blockers&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re a small development team with 3 members, working mostly on J2EE applications (but not only). We&#8217;re not afraid to get our hands dirty, and go to the darkest places in order to remove those annoying bugs <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blockers.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blockers.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blockers.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blockers.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blockers.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blockers.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blockers.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blockers.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blockers.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blockers.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blockers.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blockers.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blockers.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blockers.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blockers.wordpress.com&amp;blog=7192763&amp;post=3&amp;subd=blockers&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blockers.wordpress.com/2009/04/01/motivation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/760918d2ec8d126bc0593548de298225?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">blockers</media:title>
		</media:content>
	</item>
	</channel>
</rss>
