<?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-4134308587252322659</id><updated>2012-01-05T13:41:09.568+02:00</updated><category term='spring log logging log4j ioc'/><category term='proxy'/><category term='grub'/><category term='java thread synchronization thread-safe reordering'/><category term='gwt-rpc'/><category term='singleton'/><category term='hashcode'/><category term='map'/><category term='gwt'/><category term='event'/><category term='gin'/><category term='hibernate java IndexOutOfBoundsException ordinal'/><category term='initialization'/><category term='java string concatenation stringbuilder stringbuffer test  testcase'/><category term='spring controller web annotation maven'/><category term='spring hibernate OpenSessionInView collection HibernateException'/><category term='serializable'/><category term='set'/><category term='guice'/><category term='timer'/><category term='dual-boot'/><category term='spring'/><category term='cglib'/><category term='windows'/><category term='spring maven web nosuchmethoderror context'/><category term='maven gwt library module common'/><category term='No Hibernate Session bound to thread'/><category term='hibernate criteria distinct resulttransformer love hate'/><category term='bean initialize'/><category term='tapestry'/><category term='linux'/><category term='transactional'/><category term='hibernate'/><category term='init'/><category term='transaction'/><category term='uuid'/><category term='gwt listener listenercollection ConcurrentModificationException'/><category term='java'/><category term='rpc'/><category term='efficient'/><category term='aop'/><category term='synchronized'/><category term='iterate'/><category term='java thread synchronization thread-safe web'/><category term='js gwt ajax callback nullPointer'/><category term='stripes'/><category term='handler'/><category term='java gwt json bytearray byte encoding base64 byte array'/><category term='springmvc'/><category term='hibernate inheritance java polymorphism generics'/><category term='mvc'/><category term='click'/><category term='bit flag enum enumset'/><category term='controller'/><category term='timerTask'/><category term='struts'/><category term='advise'/><category term='persistenset'/><category term='java map containsKey equals hashCode'/><category term='ubuntu'/><category term='equals'/><category term='java hibernate enum mapping'/><title type='text'>A programmer's blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>35</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-8675951795742459303</id><published>2010-02-05T10:29:00.002+02:00</published><updated>2010-02-05T10:31:42.826+02:00</updated><title type='text'>Method calls through interface references are slower (on Android)</title><content type='html'>&lt;span class="postbody"&gt;In the 2009 Google I/O talk about writing  real-time games for Android &lt;a class="snap_shots" href="http://developer.android.com/videos/index.html#v=U4Bk5rmIpic" target="_new" rel="nofollow"&gt;http://developer.android.com/videos/index.html#v=U4Bk5rmIpic&lt;/a&gt;  it is recommended that for performance we don't use interfaces.  Supposedly the calls through an interface reference are about 30%  slower. It is also mentioned that calls to static methods are faster. &lt;br /&gt;&lt;br /&gt;In these circumstances, i asked myself if all calls to a non-direct  reference are slower. I'm not an expert at low level stuff, but it  looks to me that calling a method through a interface reference is about  the same thing as calling a method through a reference to a parent  class. But this would mean that we shouldn't use inheritance at all. And  that, for someone like me that usually trades performance for  scalability, it sounds crazy.&lt;br /&gt;&lt;br /&gt;I decided to make a quick test to see if this is true. Here's the  code I used: &lt;a class="snap_shots" href="http://pastebin.com/m7c7c0043" target="_new" rel="nofollow"&gt;http://pastebin.com/m7c7c0043&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;First I ran it on my PC and I was stupefied to find results like  these at every run:&lt;br /&gt;&lt;i&gt;Direct refference =&gt; 1,596,318,257&lt;br /&gt;Parent refference =&gt; 1,550,725,582&lt;br /&gt;Interface refference =&gt; 1,552,626,591&lt;br /&gt;Static refference =&gt; 1,751,394,872&lt;/i&gt;&lt;br /&gt;So the interface calls are about the same. Actually sometimes they  were faster by a negligible amount.&lt;br /&gt;&lt;br /&gt;Then I tested it in an Android application, using a HTC Hero Phone.  (Note: I reduced the number of iterations from 1000000000L to  5000000L).&lt;br /&gt; Results were something like:&lt;br /&gt;&lt;i&gt;Direct refference =&gt; 3,767,791,749&lt;br /&gt;Parent refference =&gt; 3,477,020,264&lt;br /&gt;Interface refference =&gt; 4,690,185,547&lt;br /&gt;Static refference =&gt; 3,327,636,719&lt;br /&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;span class="postbody"&gt;So the interfaces are slower. I can now confirm  with my own test. I guess the virtual machine is quite different.&lt;br /&gt;The good thing is that calls through parent references are not  slower. Wohoo! OOP for life  &lt;img src="http://www.coderanch.com/images/smilies/283a16da79f3aa23fe1025c96295f04f.gif" /&gt;   &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-8675951795742459303?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/8675951795742459303/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=8675951795742459303' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/8675951795742459303'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/8675951795742459303'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2010/02/method-calls-through-interface.html' title='Method calls through interface references are slower (on Android)'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-1761380440386894340</id><published>2009-11-13T16:41:00.003+02:00</published><updated>2009-11-13T16:56:04.485+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='initialization'/><category scheme='http://www.blogger.com/atom/ns#' term='gwt'/><category scheme='http://www.blogger.com/atom/ns#' term='guice'/><category scheme='http://www.blogger.com/atom/ns#' term='init'/><category scheme='http://www.blogger.com/atom/ns#' term='spring'/><category scheme='http://www.blogger.com/atom/ns#' term='gin'/><category scheme='http://www.blogger.com/atom/ns#' term='bean initialize'/><title type='text'>Simulate bean initialization in GWT with GIN</title><content type='html'>I currently use &lt;a href="http://code.google.com/p/google-gin/"&gt;Google-Gin&lt;/a&gt; in my project and I wanted a simple, clean way of calling an initialization method on some injected objects, right after all the properties have been set.&lt;br /&gt;For Spring users, this would be the equivalent of afterPropertiesSet(). Up until now this hasn't been a problem as I was doing the injection in the constructor and I could call this method myself at the end of the constructor.&lt;br /&gt;However, constructor injection and the GWT split points don't like each other so I need to do method injection (I like this better anyway).&lt;br /&gt;&lt;br /&gt;After a bit of thinking, the simplest solution I've found is the following:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;@Inject&lt;br /&gt;public void setAll(A a, B b, C c) {&lt;br /&gt;  this.setA(a);&lt;br /&gt;  this.setB(b);&lt;br /&gt;  this.setC(c);&lt;br /&gt;  &lt;span style="font-style: italic;"&gt;this.init();&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You can do the same thing as in constructor. Instead of having multiple injected setters you can have a single injected method like above.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-1761380440386894340?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/1761380440386894340/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=1761380440386894340' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/1761380440386894340'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/1761380440386894340'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/11/simulate-bean-initialization-in-gwt.html' title='Simulate bean initialization in GWT with GIN'/><author><name>Evelina</name><uri>http://www.blogger.com/profile/04395588515689391723</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://2.bp.blogspot.com/_lwzHb2ntvAU/TBtqeHpAq2I/AAAAAAAAALs/5BhG5OUQiFE/S220/Character_05_by_kinly.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-5746815320918407688</id><published>2009-08-08T22:49:00.004+03:00</published><updated>2009-08-08T23:04:52.020+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='uuid'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='hibernate'/><category scheme='http://www.blogger.com/atom/ns#' term='hashcode'/><category scheme='http://www.blogger.com/atom/ns#' term='equals'/><title type='text'>Always read the comments</title><content type='html'>I've been using the db field identity and equals + hashCode override approach suggested in &lt;a href="http://onjava.com/pub/a/onjava/2006/09/13/dont-let-hibernate-steal-your-identity.html?page=1"&gt;this article&lt;/a&gt; because the &lt;a href="https://www.hibernate.org/109.html"&gt;Hibernate official doc&lt;/a&gt; on equals seemed to have gaps.&lt;br /&gt;&lt;br /&gt;However, I only recently read the comments on that article while doing a quick research on this subject. I seems that the Hibernate team is &lt;a href="https://forum.hibernate.org/viewtopic.php?f=1&amp;amp;t=967211&amp;amp;start=30"&gt;not happy at all with it&lt;/a&gt;. If you endure to read through the annoyed and dismissive responses they give &lt;span style="font-style: italic;"&gt;(to be fair, I bed they have to repeat the same stuff to 1000 different dummy people so anyone would become dismissive)&lt;/span&gt;, you'll find out that &lt;blockquote&gt;&lt;span style="font-style: italic;"&gt;you only have to override these methods if you use detached objects. And they feel there are much better alternatives to using detached objects.&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;This brings me in the position to reconsider if I'm using &lt;span style="font-style: italic;"&gt;the right&lt;/span&gt; approach.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;ALWAYS READ ALL THE COMMENTS DUMMY!&lt;span style="font-weight: bold;"&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/4134308587252322659-5746815320918407688?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/5746815320918407688/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=5746815320918407688' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5746815320918407688'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5746815320918407688'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/08/always-read-comments.html' title='Always read the comments'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-8242287680544857620</id><published>2009-08-06T12:57:00.004+03:00</published><updated>2009-08-06T14:08:58.588+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='transactional'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='hibernate'/><category scheme='http://www.blogger.com/atom/ns#' term='transaction'/><category scheme='http://www.blogger.com/atom/ns#' term='timer'/><category scheme='http://www.blogger.com/atom/ns#' term='spring'/><category scheme='http://www.blogger.com/atom/ns#' term='timerTask'/><category scheme='http://www.blogger.com/atom/ns#' term='No Hibernate Session bound to thread'/><category scheme='http://www.blogger.com/atom/ns#' term='proxy'/><title type='text'>Hibernate + Spring + TimerTask = No Hibernate Session bound to thread</title><content type='html'>I recently come across a  problem in a Spring+Hibernate project when trying to execute an operation with a delay.&lt;br /&gt;&lt;br /&gt;I had a service bean (let's say EntityService):&lt;br /&gt;&lt;pre class="alt2" dir="ltr" style="margin: 0px; padding: 6px; overflow: auto; width: 600px; text-align: left;"&gt;public class EntityService{&lt;br /&gt;...&lt;br /&gt;@Transactional(readOnly = false)&lt;br /&gt;public void generateWithDelay(String id, long delay){&lt;br /&gt;Entity e = new Entity();&lt;br /&gt;e.setStatus("IN_CONSTRUCTION");&lt;br /&gt;e.setId(id);&lt;br /&gt;this.dao.save(e);&lt;br /&gt;this.scheduler.addTask(id, delay, this);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;@Transactional(readOnly = false)&lt;br /&gt;public void finishGeneration(String id){&lt;br /&gt;Entity e = this.dao.get(id);&lt;br /&gt;e.setStatus("DONE");&lt;br /&gt;this.dao.save(e);&lt;br /&gt;}&lt;br /&gt;....&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;I wanted to call &lt;span style="font-weight: bold;"&gt;generateWithDelay&lt;/span&gt; at a user action then after N seconds &lt;span style="font-weight: bold;"&gt;finishGeneration&lt;/span&gt; to be called.&lt;br /&gt;&lt;br /&gt;I created a "Scheduler" an &lt;span style="font-weight: bold;"&gt;addTask&lt;/span&gt; method, that accepted the delay, the parameters of the call and a callback (for wich I created a &lt;span style="font-weight: bold;"&gt;SchedulerCallback&lt;/span&gt; interface that my service implemented).&lt;br /&gt;&lt;br /&gt;Under the hood the scheduler would simply create a &lt;span style="font-weight: bold;"&gt;TimeTask&lt;/span&gt; than when the time passed it called the callback with the suplied parameters. This way the timerTask is as generic as possible and the finishGeneration is where it belongs in the entityService.&lt;br /&gt;&lt;br /&gt;All nice and joly. generateWithDelay would work ok. It ads the entity in the DB and it starts the timer. However when the timer called the finishGeneration method I would get:&lt;br /&gt;&lt;i&gt;&lt;br /&gt;org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here&lt;br /&gt;at org.springframework.orm.hibernate3.AbstractSession FactoryBean$TransactionAwareInvocationHandler.invo ke(AbstractSessionFactoryBean.java:300)&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Obviously something is wrong with the transaction. A transaction never gets created before reaching the dao even thow &lt;span style="font-weight: bold;"&gt;finishGeneration&lt;/span&gt; is annotated with &lt;span style="font-weight: bold;"&gt;@Transactional&lt;/span&gt;. The annotation should work beacause it works just fine for &lt;span style="font-weight: bold;"&gt;generateWithDealy&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;What to do? what to do? My first thought was that it's the source of the call that creates the problem. The hibernate transaction usually is the JPA transaction that the J2EE container provides. So if the call is not initiated by a user action the transaction might never get called. But I'm not running in a J2EE environment and I have:&lt;br /&gt;&lt;pre class="alt2" dir="ltr" style="margin: 0px; padding: 6px; overflow: auto; width: 600px; text-align: left;"&gt;&amp;lt;prop key="hibernate.current_session_context_class"&amp;gt;org.hibernate.transaction.JDBCTransactionFactory&amp;lt;/prop&amp;gt;&lt;br /&gt;&amp;lt;prop key="hibernate.transaction.factory_class"&amp;gt;thread&amp;lt;/prop&amp;gt;&lt;br /&gt;&lt;/pre&gt; so it can't be it.&lt;br /&gt;&lt;br /&gt;As a first fix I solved this by programatically opening a transaction in the timerTask just before invoking the callback. With springs &lt;a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/transaction/support/TransactionTemplate.html"&gt;Transaction Template&lt;/a&gt; it's actually quite easy. After this little trick it works just fine.&lt;br /&gt;&lt;br /&gt;Lucky for me I remained curious about why it won't work with declarative transaction. In the end I found the problem.&lt;br /&gt;&lt;br /&gt;When I provide the callback to the scheduler I do:&lt;br /&gt;&lt;pre class="alt2" dir="ltr" style="margin: 0px; padding: 6px; overflow: auto; width: 600px; text-align: left;"&gt;this.scheduler.addTask(id, delay, this); &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As you know, in Spring the transaction is started by the proxy that wraps the entityService. However, because I use JDK proxies, this won't be the proxy, but the proxy target (the original service). So when the callback is invoked it bypasses the transaction mechanism completely. The trick is to provide the actual proxy to the scheduler. I did this by letting EntityService implement ApplicationContextAware and BeanNameAware and fetching the proxy from the applicationContext at initialization:&lt;br /&gt;&lt;pre class="alt2" dir="ltr" style="margin: 0px; padding: 6px; overflow: auto; width: 600px; text-align: left;"&gt;&lt;br /&gt;public class EntityService implements ApplicationContextAware, BeanNameAware, InitializingBean{  &lt;br /&gt;...  &lt;br /&gt;public void setApplicationContext(ApplicationContext ac){&lt;br /&gt; this.ac = ac;&lt;br /&gt;}&lt;br /&gt;public void setBeanName(String beanName){&lt;br /&gt; this.beanName = beanName;&lt;br /&gt;}&lt;br /&gt;public void afterPropertiesSet(){&lt;br /&gt; this.myProxy = this.ac.getBean(this.beanName);&lt;br /&gt;}&lt;br /&gt;...&lt;br /&gt;@Transactional(readOnly = false)  &lt;br /&gt;public void generateWithDelay(String id, long delay){  &lt;br /&gt; Entity e = new Entity();  &lt;br /&gt; e.setStatus("IN_CONSTRUCTION");  &lt;br /&gt; e.setId(id);  &lt;br /&gt; this.dao.save(e);  &lt;br /&gt; this.scheduler.addTask(id, delay, this.myProxy);  &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-8242287680544857620?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/8242287680544857620/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=8242287680544857620' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/8242287680544857620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/8242287680544857620'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/08/hibernate-spring-timertask-no-hibernate.html' title='Hibernate + Spring + TimerTask = No Hibernate Session bound to thread'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-6730989054073187</id><published>2009-06-21T18:00:00.005+03:00</published><updated>2009-08-06T14:10:26.370+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gwt-rpc'/><category scheme='http://www.blogger.com/atom/ns#' term='hibernate'/><category scheme='http://www.blogger.com/atom/ns#' term='gwt'/><category scheme='http://www.blogger.com/atom/ns#' term='set'/><category scheme='http://www.blogger.com/atom/ns#' term='spring'/><category scheme='http://www.blogger.com/atom/ns#' term='persistenset'/><title type='text'>Spring to solve GWT - Hibernate mess</title><content type='html'>Everybody knows that GWT and Hibernate don't get together too well. At least not when you're using GWT-RPC. That's because Hibernate changes your beans when you're using collections or properties/associations with lazy fetching and GwtRpc can't serialize those beans.&lt;br /&gt;&lt;br /&gt;For example if one of your beans has a Set of other beans, when the bean will be fetched Hibernate will use it's PersistentSet implementation of Set. This implementation contains references to other complex Hibernate objects like the SessionFactory. So the serialization will fail even if your bean implements IsSerializable and follows all the serialization rules.&lt;br /&gt;&lt;br /&gt;The common solution is to force all your GwtRpc services to return a deep-copy of the bean, instead of the bean itself. This way you can use the standard collection implementations and de-proxyfy any lazy-loading properties.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-6730989054073187?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/6730989054073187/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=6730989054073187' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/6730989054073187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/6730989054073187'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/06/spring-to-solve-gwt-hibernate-mess.html' title='Spring to solve GWT - Hibernate mess'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-4375149767835139009</id><published>2009-06-15T12:25:00.002+03:00</published><updated>2009-06-15T15:16:55.914+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='gwt'/><category scheme='http://www.blogger.com/atom/ns#' term='rpc'/><category scheme='http://www.blogger.com/atom/ns#' term='serializable'/><title type='text'>GWT Type 'package.class' was not serializable and has no concrete serializable subtypes</title><content type='html'>Uhh, these pages saved me a lot of trouble! &lt;a href="http://blog.js-development.com/2008/08/strange-gwt-compiler-error-when-trying.html"&gt;Juri Strumpflohner's TechBlog: Strange GWT compiler error when trying to serialize Java objects&lt;/a&gt;, &lt;a href="http://tom.jteam.nl/?p=6"&gt;http://tom.jteam.nl/?p=6&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Note to self! don't you ever skip-read important pages as:&lt;/span&gt; &lt;a href="http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&amp;amp;s=google-web-toolkit-doc-1-5&amp;amp;t=DevGuideSerializableTypes"&gt;http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&amp;amp;s=google-web-toolkit-doc-1-5&amp;amp;t=DevGuideSerializableTypes&lt;/a&gt; and &lt;a href="http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&amp;amp;s=google-web-toolkit-doc-1-5&amp;amp;t=FAQ_RPCSerializationSupport"&gt;http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&amp;amp;s=google-web-toolkit-doc-1-5&amp;amp;t=FAQ_RPCSerializationSupport&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So basically in order to make a class gwt-serializable (the red lines were what caused my problems):&lt;br /&gt;#1. It must implement &lt;a href="http://www.blogger.com/com.google.gwt.user.client.rpc.IsSerializable"&gt;com.google.gwt.user.client.rpc.IsSerializable&lt;/a&gt;. After GWT 1.5 you can also use &lt;a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html"&gt;java.io.Serializable&lt;/a&gt;.&lt;br /&gt;#2. All non-final, non-transient instance fields are themselves serializable&lt;br /&gt;#3. Prior to GWT 1.5, it must have a public default (zero argument) constructor or no constructor at all.&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;#4. As of GWT 1.5, it must have a default (zero argument) constructor (with any access modifier) or no constructor at all. &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;#5. Not all JRE classes that implement java.io.Serializable are gwt-serializable. In my case it was java.lang.Class&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-4375149767835139009?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/4375149767835139009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=4375149767835139009' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/4375149767835139009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/4375149767835139009'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/06/gwt-compiler-error-when-trying-to.html' title='GWT Type &apos;package.class&apos; was not serializable and has no concrete serializable subtypes'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-1182627120124238</id><published>2009-05-18T18:26:00.002+03:00</published><updated>2009-08-06T16:53:38.556+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='synchronized'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='singleton'/><title type='text'>Best way to have synchronized singletons</title><content type='html'>Use the last method:&lt;br /&gt;&lt;a href="http://java-x.blogspot.com/2006/03/singleton-pattern-in-java.html"&gt;http://java-x.blogspot.com/2006/03/singleton-pattern-in-java.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-1182627120124238?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/1182627120124238/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=1182627120124238' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/1182627120124238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/1182627120124238'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/05/best-way-to-have-synchronized.html' title='Best way to have synchronized singletons'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-5158538812012092897</id><published>2009-05-18T18:00:00.002+03:00</published><updated>2009-08-06T16:54:04.433+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='map'/><category scheme='http://www.blogger.com/atom/ns#' term='efficient'/><category scheme='http://www.blogger.com/atom/ns#' term='iterate'/><title type='text'>Efficient way to iterate maps</title><content type='html'>True! I see it every day in Spring framework code.&lt;br /&gt;&lt;a href="http://jtoee.blogspot.com/2008/05/better-way-to-iterate-java-maps.html"&gt;http://jtoee.blogspot.com/2008/05/better-way-to-iterate-java-maps.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-5158538812012092897?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/5158538812012092897/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=5158538812012092897' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5158538812012092897'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5158538812012092897'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/05/efficient-way-to-itterate-maps.html' title='Efficient way to iterate maps'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-1107583572760764866</id><published>2009-05-15T14:34:00.005+03:00</published><updated>2009-08-06T16:54:35.461+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cglib'/><category scheme='http://www.blogger.com/atom/ns#' term='controller'/><category scheme='http://www.blogger.com/atom/ns#' term='advise'/><category scheme='http://www.blogger.com/atom/ns#' term='spring'/><category scheme='http://www.blogger.com/atom/ns#' term='aop'/><category scheme='http://www.blogger.com/atom/ns#' term='proxy'/><title type='text'>Advising Spring @Controllers with AOP</title><content type='html'>As I mentioned in my previous post &lt;a href="http://cristianvrabie.blogspot.com/2009/05/spring-aop-cant-advise-controllers.html"&gt;Spring AOP can't advise controllers&lt;/a&gt; the best solution is that you can use @Controller annotated beans instead of the Controller hierarchy. &lt;br /&gt;&lt;br /&gt;As I found out this gave me a headake too. When I managed to make then accept the AOP advice they wouldn't be detected as controllers. When I made them detected as controllers they wouldn't be advised. When I managed to do both request mapping annotations wouldn't work.&lt;br /&gt;&lt;br /&gt;After some poking on the Spring forums and with the help of Marten Deinum, I finally made it work exactly as I wanted. I'll share my findings with those of you having trouble using aop with controllers.&lt;br /&gt;&lt;br /&gt;So, we have the main application context (the one started by org.springframework.web.context.ContextLoaderListe ner) with one ore more xml files.&lt;br /&gt;&lt;br /&gt;Here you should instantiate the service and lower application levels beans. This can be done by placing here the beans (by xml) or by placing the component scan component that will do that for you. Make sure that your controller beans are not instantiated here.&lt;br /&gt;&lt;br /&gt;Also here you need to include the aop:aspectj-autoproxy component and the aspect beans that will advice you service (or lower levels) beans. Notice that here you can use JDK proxies or CGLIb by your choice.&lt;br /&gt;&lt;br /&gt;In the servlet context, you place the instantiation of the controllers by component scan. You can do it as xml but component scan would be preferably.&lt;br /&gt;&lt;br /&gt;Now you place another aop:aspectj-autoproxy component. Notice that you now have to specify proxy-target-class="true" because only GCLIB will work (when using JDK proxies the RequestMaping annotations will not work because they're not inherited by proxyies while they are by subclasses). You also place here the instantiation of the aspects that will advice your controllers.&lt;br /&gt;&lt;br /&gt;That's all! Because as Marten said the bean processors apply only to the current context (and the main AC and the servlet AC are two separate context just linked together), you can have JDK proxies on service beans and autwired, automapped, GCLIB advised controllers.&lt;br /&gt;&lt;br /&gt;My only concern is that this will break if Spring will decide to make bean processors work with linked application contexts (actually won't break but will force the use of CGLIB application wide).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-1107583572760764866?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/1107583572760764866/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=1107583572760764866' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/1107583572760764866'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/1107583572760764866'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/05/advising-spring-controllers-with-aop.html' title='Advising Spring @Controllers with AOP'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-5140635833900568026</id><published>2009-05-08T16:12:00.002+03:00</published><updated>2009-05-08T16:13:35.463+03:00</updated><title type='text'>Google Web Toolkit Blog: GWT and Maven - Playing Nicely Together Since 2008</title><content type='html'>Hmm, it seems my previous post about automatically downloading the GWT dependencies (&lt;a href="http://cristianvrabie.blogspot.com/2009/05/automatic-install-gwt-dependencies-with.html"&gt;http://cristianvrabie.blogspot.com/2009/05/automatic-install-gwt-dependencies-with.html&lt;/a&gt;) is a bit deprecated. You can now reference all dependencies with a compile scope as for any other artifact. Thanks to the GWT guys for a great post: &lt;a href="http://googlewebtoolkit.blogspot.com/2009/05/gwt-and-maven-playing-nicely-together.html"&gt;Google Web Toolkit Blog: GWT and Maven - Playing Nicely Together Since 2008&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-5140635833900568026?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/5140635833900568026/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=5140635833900568026' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5140635833900568026'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5140635833900568026'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/05/google-web-toolkit-blog-gwt-and-maven.html' title='Google Web Toolkit Blog: GWT and Maven - Playing Nicely Together Since 2008'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-4767315541894514592</id><published>2009-05-08T15:02:00.007+03:00</published><updated>2009-05-08T15:55:43.181+03:00</updated><title type='text'>Automatic install Gwt dependencies with Maven</title><content type='html'>From what I noticed so far, many &lt;a href="http://maven.apache.org/"&gt;Maven&lt;/a&gt;-&lt;a href="http://code.google.com/webtoolkit/"&gt;Gwt&lt;/a&gt; users fulfil the dependency to Gwt using system artifacts. This means downloading GWT manually and adding a dependency like:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;dependency&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;com.google.gwt&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;gwt-dev-windows&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;${gwt.version}&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;scope&amp;gt;system&amp;lt;/scope&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;systemPath&amp;gt;c:/gwt/gwt-dev-windows.jar&amp;lt;/systemPath&amp;gt;&lt;br /&gt;&amp;lt;/dependency&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;This will obviously not work well in a team as all must install gwt in the same location. The quick solution is to use a system variable or a property in .m2/settings.xml like this&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;systemPath&amp;gt;${env.GWT_HOME}/gwt-dev-windows.jar&amp;lt;/systemPath&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;This works well but still presents the problem that when you want to upgrade to a newer gwt version you have to instruct all the team to update their version.&lt;br /&gt;&lt;br /&gt;There is a more elegant solution to it: use the maven-dependency-plugin. Let's get started.&lt;br /&gt;First you must add this to your build &amp;raquo; plugins section in pom. This will download a zip with the specified gwt artifacts and unpack it in your local repository.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;maven-dependency-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;executions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;execution&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;id&amp;gt;unzip-gwt-libs&amp;lt;/id&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;phase&amp;gt;compile&amp;lt;/phase&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;goals&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;goal&amp;gt;unpack&amp;lt;/goal&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/goals&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactItems&amp;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;lt;artifactItem&amp;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;lt;groupId&amp;gt;com.google.gwt&amp;lt;/groupId&amp;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;lt;artifactId&amp;gt;gwt-dev&amp;lt;/artifactId&amp;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;lt;version&amp;gt;${gwt.version}&amp;lt;/version&amp;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;lt;classifier&amp;gt;${platform}-libs&amp;lt;/classifier&amp;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;lt;type&amp;gt;zip&amp;lt;/type&amp;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;lt;overWrite&amp;gt;false&amp;lt;/overWrite&amp;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;lt;/artifactItem&amp;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;lt;/artifactItems&amp;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;lt;outputDirectory&amp;gt;${settings.localRepository}/com/google/gwt/gwt-dev/${gwt.version}&amp;lt;/outputDirectory&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/execution&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/executions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/plugin&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now that the rights dependencies are in the repository you can add the dependencies:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;dependencies&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;com.google.gwt&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;gwt-servlet&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;${gwt.version}&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;com.google.gwt&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;gwt-user&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;${gwt.version}&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;com.google.gwt&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;gwt-dev&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;${gwt.version}&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;classifier&amp;gt;${platform}-libs&amp;lt;/classifier&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;type&amp;gt;zip&amp;lt;/type&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;dependency&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;com.google.gwt&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;gwt-dev&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;${gwt.version}&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;classifier&amp;gt;${platform}&amp;lt;/classifier&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/dependency&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;In case you're wondering what platform is, it's just a trick to ensure that both windows and linux users get what they need automatically:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;profiles&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;profile&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;id&amp;gt;windows&amp;lt;/id&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;activation&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;os&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;family&amp;gt;windows&amp;lt;/family&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/os&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/activation&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;properties&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;platform&amp;gt;windows&amp;lt;/platform&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/properties&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/profile&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;profile&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;id&amp;gt;linux&amp;lt;/id&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;activation&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;os&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;family&amp;gt;unix&amp;lt;/family&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/os&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/activation&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;properties&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;platform&amp;gt;linux&amp;lt;/platform&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/properties&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/profile&amp;gt;&lt;br /&gt;&amp;lt;/profiles&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Voila! Maven at it's full power.&lt;br /&gt;&lt;br /&gt;I also pasted the entire pom:&lt;br /&gt;- here it is for gwt 1.6: &lt;a href="http://www.paste-it.net/public/ud8181b/"&gt;http://www.paste-it.net/public/ud8181b/&lt;/a&gt;&lt;br /&gt;- here it is for gwt 1.5: &lt;a href="http://www.paste-it.net/public/re927e7/"&gt;http://www.paste-it.net/public/re927e7/&lt;/a&gt;&lt;br /&gt;Note that both are for projects that use the noServer option but is easy to configure them otherwise. Also, the 1.6 project uses a different plugin to compile gwt as the one i used for for 1.5 is on it's way to deprecation, and it does not support hosted mode as well in 1.6.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-4767315541894514592?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/4767315541894514592/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=4767315541894514592' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/4767315541894514592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/4767315541894514592'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/05/automatic-install-gwt-dependencies-with.html' title='Automatic install Gwt dependencies with Maven'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-3353523764938933867</id><published>2009-05-06T13:50:00.006+03:00</published><updated>2009-05-08T15:01:32.755+03:00</updated><title type='text'>Spring AOP can't advise Controllers</title><content type='html'>I recently had a problem with advising a Spring MVC controller by using &lt;a href="http://static.springframework.org/spring/docs/2.5.x/reference/aop.html"&gt;Spring AOP&lt;/a&gt;. It was the first time I tried to advise a controller method. The thing would basically not work, as that method call was never intercepted. My setup was ok as any other bean would get advised correctly.&lt;br /&gt;&lt;br /&gt;The problem is that the methods of the controller are called internally from &lt;span style="font-style: italic;"&gt;org.springframework.web.servlet.mvc.AbstractController&lt;/span&gt; and the &lt;a href="http://static.springframework.org/spring/docs/2.5.x/reference/aop.html#aop-understanding-aop-proxies"&gt;proxy method&lt;/a&gt; that Spring AOP is using can't detect such a call.&lt;br /&gt;&lt;br /&gt;The solution is to not use the Controller hierarchy. Just use beans annotated with &lt;span style="font-weight: bold;"&gt;@Controller&lt;/span&gt; and map your classes via &lt;span style="font-weight: bold;"&gt;@RequestMapping&lt;/span&gt;. This way the methods will be called via reflection by a subcomponent of the dispatcher.&lt;br /&gt;&lt;br /&gt;However, if you're stuck inheriting the Controller class, the best thing you can do is to use a poincut like &lt;span style="font-style: italic; font-weight: bold;"&gt;execution(* org.springframework.web.servlet.mvc.AbstractController.handleRequest(..))&lt;/span&gt; because this is the method that is getting called from outside. Based on what you want to do this might be or not be enough. For me this is a too generic join-point, as all controler methods would get advised and I want only a specific one to be.&lt;br /&gt;&lt;br /&gt;The foolproof solution is to use a full blown AOP solution like &lt;a href="http://www.eclipse.org/aspectj/"&gt;AspectJ&lt;/a&gt; that uses a loadtime or compile time weaving, and would be capable of intercepting an internal method call.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-3353523764938933867?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/3353523764938933867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=3353523764938933867' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/3353523764938933867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/3353523764938933867'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/05/spring-aop-cant-advise-controllers.html' title='Spring AOP can&apos;t advise Controllers'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-231903427120008362</id><published>2009-02-27T10:53:00.003+02:00</published><updated>2009-02-27T11:30:46.378+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='event'/><category scheme='http://www.blogger.com/atom/ns#' term='gwt'/><category scheme='http://www.blogger.com/atom/ns#' term='handler'/><title type='text'>New GWT Event System</title><content type='html'>Following my last post about the GWT listener collection, i found out that in GWT 1.6 a new event system is to be implemented: &lt;a href="http://code.google.com/p/google-web-toolkit-incubator/wiki/GwtEventSystem"&gt;http://code.google.com/p/google-web-toolkit-incubator/wiki/GwtEventSystem&lt;/a&gt;&lt;br /&gt;It looks pretty cool. I can hardly wait to try the new toy :D&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-231903427120008362?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/231903427120008362/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=231903427120008362' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/231903427120008362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/231903427120008362'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/02/new-gwt-event-system.html' title='New GWT Event System'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-4307764100682913731</id><published>2009-02-26T20:45:00.001+02:00</published><updated>2009-02-26T20:48:44.132+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gwt listener listenercollection ConcurrentModificationException'/><title type='text'>GWT listener collection and ConcurrentModificationException</title><content type='html'>I noticed that if you try to alter the list of a widgets listeners in the listener implementing method, you get &lt;span style="font-weight: bold;"&gt;java.util.ConcurrentModificationException: null. &lt;/span&gt;For example:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public class MyApplication implements EntryPoint, ClickListener {&lt;br /&gt;  public void onModuleLoad() {&lt;br /&gt;      Button w = new Button("clickme");&lt;br /&gt;      w.addClickListener(this);&lt;br /&gt;      RootPanel.get().add(w);&lt;br /&gt;  }&lt;br /&gt;  public void onClick(Widget sender) {&lt;br /&gt;     ((Button)sender).removeClickListener(this);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This is to be excepted since we're modifying the listener collection while iterating over it. However, this can be solved in the FocusWidget implementation by iterating over a clone of the listener collection instead of the actual collection. As result, the collection on which we iterate can never change and the behavior is consistent.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public void onBrowserEvent(Event event) {&lt;br /&gt;  switch (DOM.eventGetType(event)) {&lt;br /&gt;     case Event.ONCLICK:&lt;br /&gt;         if (clickListeners != null) {&lt;br /&gt;           &lt;span style="font-weight: bold;"&gt;clickListeners.clone().fireClick(this);&lt;/span&gt;&lt;br /&gt;      }&lt;br /&gt;      break;&lt;br /&gt;   ......&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;I don't know how often people remove listeners in the actual event, so I can't tell that the cloning of the collection is worth in the long run. If only the listener collection would be protected instead of private someone could overwrite onBrowserEvent to add this functionality on any widget that might need to remove listeners while iterating over the collection. It's better than using DefferedCommand.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-4307764100682913731?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/4307764100682913731/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=4307764100682913731' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/4307764100682913731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/4307764100682913731'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/02/gwt-listener-collection-and.html' title='GWT listener collection and ConcurrentModificationException'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-342521224125409301</id><published>2009-01-28T23:23:00.002+02:00</published><updated>2009-01-28T23:31:00.002+02:00</updated><title type='text'>Die IE6! Die!</title><content type='html'>I currently stumbled on a chart showing the &lt;a href="http://weblogs.mozillazine.org/asa/archives/2009/01/ie6_on_the_way.html"&gt;decrees in IE6 users&lt;/a&gt; and cheered on the news. As an ex WEB/SCRIPT/CSS/DO-IT-ALL developer, i know the pain of making everything right on all browsers in 10 minutes then loosing 3 days to "try" to make it look at least remotely the same on IE6.&lt;br /&gt;&lt;br /&gt;As I said on many forums damn IE6 is like a stubborn beast that just won't die. I really hope it's this year...&lt;br /&gt;And when it happens I bet many of us will still have nightmares about it :)&lt;br /&gt;&lt;br /&gt;- AAAAA!!!&lt;br /&gt;- Honey, what's wrong? Why are you crying?&lt;br /&gt;- That damn PNG won't work!&lt;br /&gt;- What?!?!&lt;br /&gt;&lt;br /&gt;Seriously now. I'm glad it's almost over! Die bastard! Die!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-342521224125409301?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/342521224125409301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=342521224125409301' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/342521224125409301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/342521224125409301'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/01/die-ie6-die.html' title='Die IE6! Die!'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-5665781596064642504</id><published>2009-01-16T17:33:00.008+02:00</published><updated>2009-01-16T18:28:03.413+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bit flag enum enumset'/><title type='text'>BitFlags and EnumSet</title><content type='html'>Have you ever had a method call like this?&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public void doSomething(MyObj obj, boolean detailed);&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Beautiful ... simple ... elegant ... until the PM decides to do have a bit more options.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public void doSomething(MyObj obj, boolean withParam1, boolean withParam2, boolean withParam3, boolean withParam4, boolean withParam5, boolean withParam6 );&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;And for the sake of backwards compatibility you do all the intermediate methods.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public void doSomething(MyObj obj);&lt;br /&gt;public void doSomething(MyObj obj, boolean withParam1 );&lt;br /&gt;public void doSomething(MyObj obj, boolean withParam1, boolean withParam2 );&lt;br /&gt;.&lt;br /&gt;..&lt;br /&gt;...&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;And each time he adds another parameter you feel like slamming your hear (or optionally his head) with the door.&lt;br /&gt;&lt;br /&gt;Well, for this situations, I discovered &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/EnumSet.html"&gt;EnumSet&lt;/a&gt; as being a very good, anti-head-slamming solution.&lt;br /&gt;&lt;br /&gt;If you get to read the &lt;a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html"&gt;dark scroll of the Java Enums&lt;/a&gt;, you'll see that there's more to the tiny Enum than you might know. In Java, Enums are not glorified integers as in other languages, but you can do all sort of interesting stuff with them as add data, add behaviour or use them as &lt;span style="font-weight:bold;"&gt;bit flags&lt;/span&gt; inside an EnumSet. And since your method really looks like it needs something like bit flags.&lt;br /&gt;&lt;br /&gt;For those of you don't know what I'm talking about, bit flags are something like &lt;a href="http://weblogs.asp.net/wim/archive/2004/04/07/109095.aspx"&gt;this&lt;/a&gt;. However Enum set looks much more civilized and since they're implemented as bit arrays, they're quite efficient. &lt;br /&gt;&lt;br /&gt;So how do you use them? First of all you need an Enum. Lets say&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public Enum DoSomethingWith{&lt;br /&gt;  PARAM1,&lt;br /&gt;  PARAM2,&lt;br /&gt;  PARAM3,&lt;br /&gt;  ...&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;then you change your method like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public void doSomething(MyObj obj, EnumSet&lt;DoSomethingWith&gt; include);&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;you call your method like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;doSomething(obj, EnumSet.of(DoSomethingWith.PARAM1, DoSomethingWith.PARAM3, DoSomethingWith.PARAM10));&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;and you check like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;if(include.contains(DoSomethingWith.PARAM3)){...}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Way to go EnumSet! That's until your PM decides to add a non boolean parameter to the method :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-5665781596064642504?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/5665781596064642504/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=5665781596064642504' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5665781596064642504'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5665781596064642504'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/01/bitflags-and-enumset.html' title='BitFlags and EnumSet'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-488147944477758253</id><published>2009-01-16T14:32:00.013+02:00</published><updated>2009-01-16T18:29:53.982+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java string concatenation stringbuilder stringbuffer test  testcase'/><title type='text'>StringBuilder vs. String</title><content type='html'>While writing an &lt;span style="font-style: italic;"&gt;serializer &lt;/span&gt;i suddenly and concatenating strings like hell i suddenly remembered that Strings are in fact immutable objects and might be actually inefficient to do a lot of concatenations. So i started to read about String vs StringBuffer vs StringBuilder (the younger faster, not thread-safe, brother of StringBuffer).&lt;br /&gt;&lt;br /&gt;Man, I'm telling you, it's a fight out there. Everybody is throwing "specialist" opinions left and right. So i still don't know if&lt;br /&gt;&lt;code&gt;&lt;br /&gt;String s = "a" + var + "b";&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;is or is not faster than&lt;br /&gt;&lt;code&gt;&lt;br /&gt;StringBuilder sb = new StringBuilder();&lt;br /&gt;s.append("a");&lt;br /&gt;s.append(var);&lt;br /&gt;s.append("b");&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Anyway, my opinion is that for simple operations there's no damn difference. It doesn't matter anyway. Loop operations are those that matter. I won't start using StringBuilder for "a"+"b". So even though I've seen tons of decompiled bytecode and sf theories, I haven't seen a single real case time. So I did a quick one (note that the situation might not be very realistic to you but it makes sense to some scenarios I've been throough like my serializer) :&lt;br /&gt;&lt;code&gt;&lt;br /&gt;int[] runfor = {10,100,1000,10000,100000};&lt;br /&gt;  String a = "fdafdsf";&lt;br /&gt;  String b = "sjnfadhbfdsaf";&lt;br /&gt;  int buffersize = a.length()+b.length();&lt;br /&gt;  &lt;br /&gt;  for(int i=0; i&amp;lt;runfor.length;i++){&lt;br /&gt;   long start = System.currentTimeMillis();&lt;br /&gt;   String s = "";&lt;br /&gt;   for(int j=0;j&amp;lt;runfor[i];j++){&lt;br /&gt;    s += a + "--" + b;&lt;br /&gt;   }&lt;br /&gt;   long end = System.currentTimeMillis();&lt;br /&gt;   System.out.println("String concatenation x "+runfor[i]+" times: "+(end-start)+" miliseconds");&lt;br /&gt;   &lt;br /&gt;   start = System.currentTimeMillis();&lt;br /&gt;   StringBuilder sb = new StringBuilder();&lt;br /&gt;   for(int j=0;j&amp;lt;runfor[i];j++){&lt;br /&gt;    sb.append(a);&lt;br /&gt;    sb.append("--");&lt;br /&gt;    sb.append(b);&lt;br /&gt;   }&lt;br /&gt;   end = System.currentTimeMillis();&lt;br /&gt;   System.out.println("StringBuilder concatenation x "+runfor[i]+" times: "+(end-start)+" miliseconds");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;And, damn, I was surprised!!&lt;style type="text/css"&gt;  &lt;!--   @page { margin: 0.79in }   TD P { margin-bottom: 0in }   TH P { margin-bottom: 0in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;table width="100%" border="1" bordercolor="#000000" cellpadding="4" cellspacing="0"&gt;  &lt;col width="85"&gt;  &lt;col width="85"&gt;  &lt;col width="85"&gt;  &lt;tbody&gt;&lt;tr valign="top"&gt;   &lt;th width="33%"&gt;    &lt;p align="center"&gt;# Runs&lt;/p&gt;   &lt;/th&gt;   &lt;th width="33%"&gt;    &lt;p align="center"&gt;Time for String concatenation (milliseconds)&lt;/p&gt;   &lt;/th&gt;   &lt;th width="33%"&gt;    &lt;p align="center"&gt;Time for StringBuffer append&lt;/p&gt;   &lt;/th&gt;  &lt;/tr&gt;  &lt;tr valign="top"&gt;   &lt;td sdval="10" sdnum="1033;0;#,##0" width="33%"&gt;    &lt;p align="center"&gt;10&lt;/p&gt;   &lt;/td&gt;   &lt;td sdval="0" sdnum="1033;" width="33%"&gt;    &lt;p align="center"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td sdval="0" sdnum="1033;" width="33%"&gt;    &lt;p align="center"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr valign="top"&gt;   &lt;td sdval="100" sdnum="1033;0;#,##0" width="33%"&gt;    &lt;p align="center"&gt;100&lt;/p&gt;   &lt;/td&gt;   &lt;td sdval="2" sdnum="1033;" width="33%"&gt;    &lt;p align="center"&gt;&lt;b&gt;2&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td sdval="0" sdnum="1033;" width="33%"&gt;    &lt;p align="center"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr valign="top"&gt;   &lt;td sdval="1000" sdnum="1033;0;#,##0" width="33%"&gt;    &lt;p align="center"&gt;1,000&lt;/p&gt;   &lt;/td&gt;   &lt;td sdval="37" sdnum="1033;" width="33%"&gt;    &lt;p align="center"&gt;&lt;b&gt;37&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td sdval="0" sdnum="1033;" width="33%"&gt;    &lt;p align="center"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr valign="top"&gt;   &lt;td sdval="10000" sdnum="1033;0;#,##0" width="33%"&gt;    &lt;p align="center"&gt;10,000&lt;/p&gt;   &lt;/td&gt;   &lt;td sdval="15888" sdnum="1033;" width="33%"&gt;    &lt;p align="center"&gt;&lt;b&gt;15888&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td sdval="3" sdnum="1033;" width="33%"&gt;    &lt;p align="center"&gt;&lt;b&gt;3&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr valign="top"&gt;   &lt;td sdval="100000" sdnum="1033;0;#,##0" width="33%"&gt;    &lt;p align="center"&gt;100,000&lt;/p&gt;   &lt;/td&gt;   &lt;td width="33%"&gt;    &lt;p style="font-weight: normal;" align="center"&gt;&lt;i&gt;GOT BORED WAITING&lt;/i&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td sdval="49" sdnum="1033;" width="33%"&gt;    &lt;p align="center"&gt;&lt;b&gt;49&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;p style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/p&gt;At first I thought that i divided the string buffer by 1000 as to display it in seconds. :) Hmm.. and there were people actually saying that they'll give up performance for clarity any time of the day. Hmm.. &lt;span style="font-weight: bold;"&gt;Obfuscation forever baby!&lt;/span&gt; :)))&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-488147944477758253?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/488147944477758253/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=488147944477758253' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/488147944477758253'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/488147944477758253'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/01/stringbuilder-vs-string.html' title='StringBuilder vs. String'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-5944898120381689749</id><published>2009-01-14T22:57:00.004+02:00</published><updated>2009-01-14T23:11:15.956+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hibernate criteria distinct resulttransformer love hate'/><title type='text'>Hibernate Love and Hate relationship</title><content type='html'>I was just praising Hibernate a few days ago for how much it helps with simplifying your work, reducing boilerplate code and how well lazy loading works, actually making it enjoyable to work with RDBs, when I hit another major limitation. It seems you can't perform a &lt;b&gt;DISTINCT&lt;/b&gt; query via Hibernate Criteria API :|&lt;br /&gt;&lt;br /&gt;The only workaround for it is to use a ResultTransformer but which runs at memory level (so if you have a result set of hundred of items you're screwed) and has the bad habit of not working all the time. &lt;br /&gt;&lt;code&gt;.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)&lt;/code&gt;&lt;br /&gt;Plus, you cannot use this with limit because if you use limit 10 and from those 5 are duplicates, you will have random result number :|&lt;br /&gt;&lt;br /&gt;A Jira issue is opened since 2003 &lt;a href="http://opensource.atlassian.com/projects/hibernate/browse/HB-520"&gt;http://opensource.atlassian.com/projects/hibernate/browse/HB-520&lt;/a&gt; and just sits there with tens of votes.&lt;br /&gt;&lt;br /&gt;I'm telling you, this "Hibernate" experience it's one bumpy carousel. You don't know what tomorrow might bring.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-5944898120381689749?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/5944898120381689749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=5944898120381689749' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5944898120381689749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5944898120381689749'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/01/hibernate-love-and-hate-relationship.html' title='Hibernate Love and Hate relationship'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-6836965935814321440</id><published>2009-01-08T10:08:00.005+02:00</published><updated>2009-01-08T10:47:02.803+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='js gwt ajax callback nullPointer'/><title type='text'>My server is too fast</title><content type='html'>I was currently working on a GWT application when I had some problems involving null pointers :) Ok, ok, i know that should not be happening to a "pro" developer but hang on a bit..&lt;br /&gt;So i was doing something like this:&lt;br /&gt;&lt;br /&gt;- expect triggering event&lt;br /&gt;- send ajax call&lt;br /&gt;- draw stuff&lt;br /&gt;- receive ajax response&lt;br /&gt;- use the received data to complete the drawing&lt;br /&gt;&lt;br /&gt;The reason why I was sending Ajax call first was so the response time is:&lt;br /&gt;&lt;br /&gt;|----------| (draw time)&lt;br /&gt;|-----------------------| (ajax request time) - this is the actual time because the draw and request run in parallel&lt;br /&gt;&lt;br /&gt;instead of&lt;br /&gt;|----------||-----------------------|&lt;br /&gt;(draw time) (ajax request time)&lt;br /&gt;&lt;br /&gt;However, i haven't counted that the ajax response might be back before JS finishes drawing. That never happened before to me so that's my only excuse. So when the response was back the elements i needed were not there yet thus the null pointer exceptions.&lt;br /&gt;&lt;br /&gt;Ofcourse the fix is quick:&lt;br /&gt;&lt;br /&gt;in drawing:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;doneDrawing = false;&lt;br /&gt;hasUnrenderedData = false;&lt;br /&gt;unrenderedData = null;&lt;br /&gt;sendAjaxCall();&lt;br /&gt;draw();&lt;br /&gt;if(hasUnrenderedData){&lt;br /&gt; callback(unrenderedData);&lt;br /&gt; unrenderedData = null;&lt;br /&gt; hasUnrenderedData = false;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;in callback:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;if(doneDrawing){&lt;br /&gt; finishDrawing();&lt;br /&gt;}else{&lt;br /&gt; unrenderedData = deserialize(response);&lt;br /&gt; hasUnrenderedData = true;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Hope I learned from this and I don't shame myself again like this :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-6836965935814321440?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/6836965935814321440/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=6836965935814321440' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/6836965935814321440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/6836965935814321440'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2009/01/my-server-is-too-fast.html' title='My server is too fast'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-4818044998715046656</id><published>2008-12-25T02:12:00.002+02:00</published><updated>2008-12-25T02:27:01.701+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java gwt json bytearray byte encoding base64 byte array'/><title type='text'>ByteArray in JSON</title><content type='html'>I recently found out that string transmitted thought JSON can't be as wild as you may wish them to be. &lt;br /&gt;&lt;br /&gt;I wanted to bundle some variables into a byte array then convert it to a string and transmit it as a string property of a json object. The purpose was to obtain the shortest possible message. It would look something like:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;{"bytes":"","otherProperty":"etc..."} &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Well, it seems that this is not right. Or at least some JSON validators tell me (since the string obviously contains non printable characters). After some Java Ranch posting I found out that this also happens to SOAP messages so if it's not a standard (as i haven't seen anywhere in the JSON documentation), it's at least a tacit agreement.&lt;br /&gt;&lt;br /&gt;The only thing left to do is to apply a base64 encoding to the string which gets rid of all the problems and keeps my string as short as it can be. I also found a nice  &lt;a href="http://www.source-code.biz/snippets/java/2.htm"&gt;converter script&lt;/a&gt; which i can use both on server side and gwt client side (praise you google for your miracle invention! :) )&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-4818044998715046656?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/4818044998715046656/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=4818044998715046656' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/4818044998715046656'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/4818044998715046656'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/12/bytearray-in-json.html' title='ByteArray in JSON'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-2289326580294796628</id><published>2008-12-15T08:37:00.003+02:00</published><updated>2008-12-15T09:08:20.199+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='maven gwt library module common'/><title type='text'>GWT Module projects with Maven</title><content type='html'>I recently had the necessity to break a GWT-Maven project into multiple subprojects. The situation is pretty common: 2 or more projects used the same code so I had to make a commons module (library). I wasn't quite sure how the &lt;a href="http://code.google.com/p/gwt-maven/"&gt;maven-googlewebtoolkit2-plugin&lt;/a&gt;, that I use, was handling this but finally nailed it down.&lt;br /&gt;&lt;br /&gt;So the trick is to have the commons project packed as a jar, opposed to a standard entry point project that would be packed in a war. The absolute critical aspect of this is to include the source *.java files in the jar. I do this by using the maven-resources plugin in the pom file of the library project:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  &amp;lt;build&amp;gt;&lt;br /&gt;  &amp;lt;resources&amp;gt;&lt;br /&gt;    &amp;lt;resource&amp;gt;&lt;br /&gt;      &amp;lt;directory&amp;gt;src/main/java&amp;lt;/directory&amp;gt;&lt;br /&gt;      &amp;lt;includes&amp;gt;&lt;br /&gt;        &amp;lt;include&amp;gt;**/client/**&amp;lt;/include&amp;gt;&lt;br /&gt;        &amp;lt;include&amp;gt;**/public/**&amp;lt;/include&amp;gt;&lt;br /&gt;      &amp;lt;/includes&amp;gt;&lt;br /&gt;    &amp;lt;/resource&amp;gt;&lt;br /&gt;    &amp;lt;resource&amp;gt;&lt;br /&gt;      &amp;lt;directory&amp;gt;src/main/resources&amp;lt;/directory&amp;gt;&lt;br /&gt;      &amp;lt;includes&amp;gt;&lt;br /&gt;        &amp;lt;include&amp;gt;**/client/**&amp;lt;/include&amp;gt;&lt;br /&gt;        &amp;lt;include&amp;gt;**/public/**&amp;lt;/include&amp;gt;&lt;br /&gt;        &amp;lt;include&amp;gt;**/*.gwt.xml&amp;lt;/include&amp;gt;&lt;br /&gt;      &amp;lt;/includes&amp;gt;&lt;br /&gt;    &amp;lt;/resource&amp;gt;&lt;br /&gt;  &amp;lt;/resources&amp;gt;&lt;br /&gt;  &amp;lt;/build&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;I also used include on the resources folder because i place my .properties file (or any non-java file) in there.&lt;br /&gt;&lt;br /&gt;Ok. Good. Now we have a jar that includes the source file (note that we didn't applied any gwt compilation - that will be done by the including project). We install it with a classic:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;mvn install&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Going to the gwt project that includes the library, i use a normal dependency include.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&amp;lt;dependencies&amp;gt;&lt;br /&gt;    &amp;lt;dependency&amp;gt;&lt;br /&gt;      &amp;lt;groupId&amp;gt;com.myproject&amp;lt;/groupId&amp;gt;&lt;br /&gt;      &amp;lt;artifactId&amp;gt;gwt-commons&amp;lt;/artifactId&amp;gt;&lt;br /&gt;      &amp;lt;version&amp;gt;${myproject.commons.version}&amp;lt;/version&amp;gt;&lt;br /&gt;    &amp;lt;/dependency&amp;gt;&lt;br /&gt;  &amp;lt;/dependencies&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Because of this, the maven-googlewebtoolkit2-plugin will add the path to the jar file to the classpath before executing the compile.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Note:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;I noticed that if the project includes a lot of modules you might get a "line too long" from windows. A common solution is to move the local maven repository to a shorter location: for example C:/.m2/.. rather than C:/Documents and Settings/../.m2/..&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now, all that is left is to include the maven-googlewebtoolkit2-plugin as usual:&lt;br /&gt;&lt;code&gt;&lt;br /&gt; &amp;lt;build&amp;gt;&lt;br /&gt;    &amp;lt;plugins&amp;gt;&lt;br /&gt;      &amp;lt;plugin&amp;gt;&lt;br /&gt;        &amp;lt;groupId&amp;gt;com.totsp.gwt&amp;lt;/groupId&amp;gt;&lt;br /&gt;        &amp;lt;artifactId&amp;gt;maven-googlewebtoolkit2-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;        &amp;lt;version&amp;gt;${maven.gwt.compiler.version}&amp;lt;/version&amp;gt;&lt;br /&gt;        &amp;lt;configuration&amp;gt;&lt;br /&gt;                &lt;br /&gt;          &amp;lt;logLevel&amp;gt;${gwt.compile.log.level}&amp;lt;/logLevel&amp;gt;&lt;br /&gt;          &lt;br /&gt;          &amp;lt;extraJvmArgs&amp;gt;${gwt.compiler.memory}&amp;lt;/extraJvmArgs&amp;gt;&lt;br /&gt;          &lt;br /&gt;          &amp;lt;style&amp;gt;${gwt.compiler.codestyle}&amp;lt;/style&amp;gt;&lt;br /&gt;          &lt;br /&gt;          &amp;lt;noServer&amp;gt;${gwt.noserver}&amp;lt;/noServer&amp;gt;&lt;br /&gt;          &amp;lt;port&amp;gt;${gwt.port}&amp;lt;/port&amp;gt;&lt;br /&gt;          &lt;br /&gt;          &amp;lt;runTarget&amp;gt;myproject-web/com.myproject.MyProject/index.html&amp;lt;/runTarget&amp;gt;&lt;br /&gt;          &lt;br /&gt;          &amp;lt;compileTargets&amp;gt;&lt;br /&gt;            &amp;lt;param&amp;gt;com.myproject.MyProject&amp;lt;/param&amp;gt;&lt;br /&gt;          &amp;lt;/compileTargets&amp;gt;&lt;br /&gt;                    &lt;br /&gt;          &amp;lt;generatorDestinationPackage&amp;gt;com.myproject.client&amp;lt;/generatorDestinationPackage&amp;gt;&lt;br /&gt;          &amp;lt;generateGettersAndSetters&amp;gt;true&amp;lt;/generateGettersAndSetters&amp;gt;&lt;br /&gt;          &lt;br /&gt;        &amp;lt;/configuration&amp;gt;&lt;br /&gt;        &lt;br /&gt;      &amp;lt;executions&amp;gt;&lt;br /&gt;        &amp;lt;execution&amp;gt;&lt;br /&gt;          &amp;lt;goals&amp;gt;&lt;br /&gt;            &amp;lt;goal&amp;gt;compile&amp;lt;/goal&amp;gt;&lt;br /&gt;          &amp;lt;/goals&amp;gt;&lt;br /&gt;        &amp;lt;/execution&amp;gt;&lt;br /&gt;        &lt;br /&gt;        &amp;lt;execution&amp;gt;&lt;br /&gt;          &amp;lt;id&amp;gt;compile&amp;lt;/id&amp;gt;&lt;br /&gt;          &amp;lt;phase&amp;gt;process-classes&amp;lt;/phase&amp;gt;&lt;br /&gt;          &amp;lt;goals&amp;gt;&lt;br /&gt;            &amp;lt;goal&amp;gt;compile&amp;lt;/goal&amp;gt;&lt;br /&gt;          &amp;lt;/goals&amp;gt;&lt;br /&gt;        &amp;lt;/execution&amp;gt;&lt;br /&gt;        &lt;br /&gt;      &amp;lt;/executions&amp;gt;&lt;br /&gt;      &amp;lt;/plugin&amp;gt;      &lt;br /&gt;    &amp;lt;/plugins&amp;gt;      &lt;br /&gt;&amp;lt;/build&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt; &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Note:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;Note that you have to have defined the properties used by through the pom files like ${gwt.compiler.codestyle}. For more information about what values can these have, have a look at the &lt;a href="http://gwt-maven.googlecode.com/svn/docs/maven-googlewebtoolkit2-plugin/compile-mojo.html"&gt;gwtmaven documentation&lt;/a&gt;.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-2289326580294796628?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/2289326580294796628/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=2289326580294796628' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/2289326580294796628'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/2289326580294796628'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/12/gwt-module-projects-with-maven.html' title='GWT Module projects with Maven'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-7482454866882422380</id><published>2008-11-26T14:55:00.005+02:00</published><updated>2008-11-26T17:11:13.543+02:00</updated><title type='text'>Hibernate is ultra-sensible at collections!</title><content type='html'>Found (another) tricky thing about Hibernate. &lt;br /&gt;&lt;br /&gt;To be honestly is starting to piss me off. Maybe because I still don't have the experience to steer clear of these problems or i just miss the old days when I was writing every query with my own hand and everything that happened was so predictable.&lt;br /&gt;&lt;br /&gt;So I have a standard class A that in the hbm mapping has a bag of objects B. I wanted to use bag because they say everywhere that bags are very efficient. However in my class i use a HashMap to store the B objects so it's easier to manage them. The key of the map is a property from the B object itself.&lt;br /&gt;&lt;br /&gt;To make the conversion i use a trick in the setter/getter:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public class B{&lt;br /&gt;  private String name;&lt;br /&gt;  //.. other properties&lt;br /&gt;  //.. setter and getters&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class A{&lt;br /&gt;  HashMap&amp;lt;String,B&amp;gt; objs;&lt;br /&gt;  public Collection&amp;lt;B&amp;gt; getObjs(){&lt;br /&gt;    return this.objs.values();&lt;br /&gt;  }&lt;br /&gt;  public setObjs(Collection&amp;lt;B&amp;gt; objs){&lt;br /&gt;    for(B o:objs){&lt;br /&gt;      this.objs.put(o.getName(),o);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This seems not to be on the liking of Hibernate, and a simple get to an object A seems to trigger an update in the database. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;A a = dao.get( id_of_a );&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;My guess is that before the session closing, a is checked for modifications and the hash code in A.getObjs() is obviously different than when hibernate originally put it there, this triggering an update.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-7482454866882422380?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/7482454866882422380/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=7482454866882422380' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/7482454866882422380'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/7482454866882422380'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/11/hibernate-is-ultra-sensible-at.html' title='Hibernate is ultra-sensible at collections!'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-2326439832859801958</id><published>2008-11-20T11:05:00.005+02:00</published><updated>2008-11-20T11:13:15.279+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hibernate java IndexOutOfBoundsException ordinal'/><title type='text'>Remember that ordinal parameters are 1-based!</title><content type='html'>I recently came across java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based! I decided to mark this down because it's not that common and can be quite ambiguous.&lt;br /&gt;&lt;br /&gt;For example, the first time i got this it was because i provided an array with to many parameters to a query:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Object[] params={ "usr","usr@gmail.com","some other", "parameters",2, 3 };&lt;br /&gt;getHibernateTemplate().find( "from User user where user.username=? and user.email=?, params)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The second time was even more ambiguous:&lt;br /&gt;I got this because i haven't mapped a file. For example, if I have a User entity and i forget to add User.hbm.xml to the hibernate.cfg file but no other entity points to User, then it won't fail at startup because hibernate can't possible know that we need that entity. It will however fail when having a query request the entity, but not with a nice "not known entity" exception but with &lt;i&gt;java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!&lt;/i&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-2326439832859801958?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/2326439832859801958/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=2326439832859801958' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/2326439832859801958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/2326439832859801958'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/11/remember-that-ordinal-parameters-are-1.html' title='Remember that ordinal parameters are 1-based!'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-3577250286942543369</id><published>2008-11-20T00:29:00.000+02:00</published><updated>2008-11-20T00:33:42.706+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java hibernate enum mapping'/><title type='text'>Hibernate enhanced Enum Mapping to String</title><content type='html'>Found a nice &lt;a href="http://www.hibernate.org/272.html"&gt;"enhanced" method&lt;/a&gt; of mapping Enums to Char/Varchar in Hibernate which requires only one class, opposed to the  &lt;a href="http://www.hibernate.org/265.html"&gt;standard hibernate method&lt;/a&gt; in which you would need to create a class for every type of enum you wanted to map. Further more, you can use this as id or as discriminator.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-3577250286942543369?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/3577250286942543369/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=3577250286942543369' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/3577250286942543369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/3577250286942543369'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/11/hibernate-enhanced-enum-mapping-to.html' title='Hibernate enhanced Enum Mapping to String'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-2583558255122870943</id><published>2008-11-19T23:45:00.006+02:00</published><updated>2008-11-20T00:04:55.771+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java thread synchronization thread-safe reordering'/><title type='text'>Downright weird things about how programs are executed!</title><content type='html'>Following my previous post &lt;a href="http://cristianvrabie.blogspot.com/2008/11/paranoid-about-concurency-in-spring-web.html"&gt;Paranoid about concurency in a Spring web application&lt;/a&gt;, by reading the first 2 chapters of &lt;a href="http://tinyurl.com/5rb5tm"&gt;Java Concurrency in Practice&lt;/a&gt; - which by now i found it's a very good book; i recommended to anyone who's into threads - i found some downright stupefying things about how programs are run and what problems you have to think about.&lt;br /&gt;&lt;br /&gt;Let's take this simple example:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public class A{&lt;br /&gt;    private static boolean ready;&lt;br /&gt;    private static int number;&lt;br /&gt;&lt;br /&gt;   private static class ReaderThread extends Thread{&lt;br /&gt;          public void run(){&lt;br /&gt;           while(!ready)&lt;br /&gt;                     Thread.yield();&lt;br /&gt;                System.out.println(number);&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;    public static void main(String[] args){&lt;br /&gt;          new ReaderThread().start();&lt;br /&gt;          number = 42;&lt;br /&gt;          ready = true;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;What can go wrong you say?! The thread will wait till the other thread sets ready to true, by then number will be set and we will print 42.&lt;br /&gt;&lt;br /&gt;NOT THAT FAST! It seams since in the main thread there's no special need to have the 2 assignments in a certain order, the processor or jvm might decide to run them in a different order. So ready might be called before number is set! Hmmm.. this is something new :)&lt;br /&gt;&lt;br /&gt;To quote from the book:&lt;br /&gt;&lt;blockquote&gt;In the absence of synchronization, the compiler, processor, and runtime can do some downright weird things to the order in which operations appear to execute. Attempts to reason about the order in which memory actions "must" happen in insufficiently synchronized multithreaded programs will almost certainly be incorrect.&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-2583558255122870943?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/2583558255122870943/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=2583558255122870943' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/2583558255122870943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/2583558255122870943'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/11/following-my-previous-post-paranoid.html' title='Downright weird things about how programs are executed!'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-3310957076533784870</id><published>2008-11-05T18:11:00.003+02:00</published><updated>2008-11-19T23:43:14.435+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java thread synchronization thread-safe web'/><title type='text'>Paranoid about concurency in a Spring web application</title><content type='html'>After some "light" reading in (in &lt;a href="http://tinyurl.com/5rb5tm"&gt;Java Concurrency in Practice&lt;/a&gt;  and &lt;a href="http://tinyurl.com/5kgyj6"&gt;Patterns of Enterprise Application Architecture&lt;/a&gt;) i became a bit paranoid about possible concurrency problems in a simple Web Application.&lt;br /&gt;&lt;br /&gt;To quote the authors of Java Concurrency in Practice - &lt;span style="font-style:italic;"&gt; chapter 1.4 Threads are everywhere&lt;/span&gt; - &lt;blockquote&gt;Even if your program never explicitly creates a thread, frameworks may create threads on your behalf, and code called from these threads mus be thread safe. [...] Frameworks introduce concurrency into applications by calling application components from framework threads. &lt;/blockquote&gt; Then there's a listing of some very usual and used frameworks that make use of thread and might add problems to your otherwise liniar code:&lt;br /&gt;- Timer&lt;br /&gt;- Swing and AWT&lt;br /&gt;- RMI&lt;br /&gt;- Servlets and JSP&lt;br /&gt;&lt;br /&gt;Putted shortly:&lt;span style="font-weight:bold;"&gt; EVERYWHERE!!!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;With this fresh in mind I placed some posts on the Spring and JavaRanch forums in search of confirmation: "a simple web app application do present concurrency problems". You can view the posts here (and admire my horrible sketches): &lt;a href="http://forum.springframework.org/showthread.php?p=211392#post211392"&gt;http://forum.springframework.org/showthread.php?p=211392#post211392&lt;/a&gt;, &lt;br /&gt;&lt;a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=83&amp;t=001935"&gt;http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=83&amp;t=001935&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;And it is true. Since Spring creates a single object used by all incoming servlet threads all the application down to database access is on the access-path of those threads and must be thread-safe. &lt;br /&gt;&lt;br /&gt;There is a positive side though. Thread-safety problems only apply to "mutable state access" of the object. Meaning that if you service to dao classes just forward method calls and use variables local to methods these will be saved on the execution stack and not made visible to separate threads. As long as you don't have properties in these objects you're safe. This is however of small consolation because the projects i usually work are rarely that simple.&lt;br /&gt;&lt;br /&gt;Bottom line: I got to finish reading those 2 books!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-3310957076533784870?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/3310957076533784870/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=3310957076533784870' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/3310957076533784870'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/3310957076533784870'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/11/paranoid-about-concurency-in-spring-web.html' title='Paranoid about concurency in a Spring web application'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-2828218042548272892</id><published>2008-11-04T09:52:00.004+02:00</published><updated>2008-11-05T18:14:54.610+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='spring hibernate OpenSessionInView collection HibernateException'/><title type='text'>How OpenSessionInViewFilter can mess with your head :)</title><content type='html'>I recently started having some troubles in a Spring - Hibernate web application. I kept receiving &lt;code&gt;org.springframework.orm.jpa.JpaSystemException: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions;&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;At first I thought that it's because I'm not using transactions and the Spring wrapper for Hibernate Session (HibernateTemplate) is not reusing the session so I was doing something like:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;My Controller -&gt; My Dao -&gt; HibernateTemplate -&gt; Get New Hibernate Session -&gt; Get A Object With An Associated Map;&lt;br /&gt;My Controller -&gt; Change something in the associated map of the object&lt;br /&gt;My Controller -&gt; My Dao -&gt; HibernateTemplate -&gt; Get New Hibernate Session -&gt; Update the object&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This would certainly explain the error since i was getting a collection from one session and saving it with other, thing not possible with Hibernate.&lt;br /&gt;&lt;br /&gt;So I tried the normal fix, to release the lock on the collection from the first session and reattach it to the second session. Big was my surprise when that didn't work as expected. I kept getting ugly new exceptions.&lt;br /&gt;&lt;br /&gt;I directed my attention on my other possible cause. Having two session opened at once (though not a direct cause, this might occasionally lead to &lt;code&gt;Illegal attempt to associate a collection with two open sessions&lt;/code&gt;. The other session I had opened was the one Spring was opening for me through OpenSessionInViewFilter. Once I removed the filter, surprise surprise, everything works OK.&lt;br /&gt;&lt;br /&gt;Now, removing OpenSessionInViewFilter is not by far an ideal solution. I would hate to eager fetch all lazy associated objects for view. &lt;br /&gt;&lt;br /&gt;The solution that would solve the problem and keep the OpenSessionInViewFilter would be to force the filter to reuse the old session (the &lt;code&gt;singleSession&lt;/code&gt; parameter) but that is know to cause other ugly problems. I will have to look into this and check for a better solution.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-2828218042548272892?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/2828218042548272892/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=2828218042548272892' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/2828218042548272892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/2828218042548272892'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/11/how-opensessioninviewfilter-can-mess.html' title='How OpenSessionInViewFilter can mess with your head :)'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-767754000273903527</id><published>2008-10-29T20:37:00.008+02:00</published><updated>2008-11-05T18:13:38.893+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='spring maven web nosuchmethoderror context'/><title type='text'>The - java.lang.NoSuchMethodError: ConfigurableWebApplicationContext.setConfigLocation - hell !!!</title><content type='html'>I recently had a lot of trouble with a Spring-Maven project. I kept getting this error when starting the web server.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.setConfigLocation (Ljava/lang/String;)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Apparently the problem was that one of my dependencies (in my case &lt;code&gt;net.sf.gwt-widget.gwt-sl&lt;/code&gt;) was introducing &lt;code&gt;org.springframework.spring:2.5.1&lt;/code&gt; as a dependency, and having this and &lt;code&gt;org.springframework.spring-webmvc&lt;/code&gt; together breaks something.&lt;br /&gt;&lt;br /&gt;I resolved the problem by excluding the &lt;code&gt;org.springframework.spring&lt;/code&gt; dependency as I didn't needed it anyway. &lt;br /&gt;&lt;br /&gt;Thanks to ram-2008 for posting the solution on this thread: http://forum.springframework.org/showthread.php?p=198644&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-767754000273903527?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/767754000273903527/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=767754000273903527' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/767754000273903527'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/767754000273903527'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/10/javalangnosuchmethoderror.html' title='The - java.lang.NoSuchMethodError: ConfigurableWebApplicationContext.setConfigLocation - hell !!!'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-909902309846851251</id><published>2008-10-29T20:15:00.004+02:00</published><updated>2008-11-05T18:12:46.486+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='spring controller web annotation maven'/><title type='text'>Where in the world is the @Controller Spring annotation?!?!</title><content type='html'>I recently found myself in the situation of banging my head on the wall when in a Maven - Spring project, in which I used &lt;code&gt;org.springframework.spring-webmvc&lt;/code&gt; (version 2.5.5), the &lt;code&gt;@Controller&lt;/code&gt; annotation could not been resolved.&lt;br /&gt;&lt;br /&gt;After some digging in the spring pom files i found that the annotation is not actually defined in the &lt;code&gt;spring-web&lt;/code&gt; or &lt;code&gt;spring-webmvc&lt;/code&gt; packages, but in the &lt;code&gt;spring-context&lt;/code&gt; package. Weirdly enough &lt;code&gt;spring-context&lt;/code&gt; is a dependency in &lt;code&gt;spring-webmvc&lt;/code&gt; but for some reason is not propagating to my project. &lt;br /&gt;&lt;br /&gt;Even more strange, the dependency is resolved if I include the maven &lt;code&gt;org.springframework.spring&lt;/code&gt; artifact where are bundled a bunch of spring dependencies but no spring code.&lt;br /&gt;&lt;br /&gt;The quick fix I used is to include &lt;code&gt;org.spring-framework.spring-context&lt;/code&gt; in my dependencies list and everything works OK, but the matter worth more digging as it may lead at the discovery of bug either in the spring pom files or even in maven.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-909902309846851251?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/909902309846851251/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=909902309846851251' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/909902309846851251'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/909902309846851251'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/10/where-in-world-is-controller-spring.html' title='Where in the world is the @Controller Spring annotation?!?!'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-5114389829289708773</id><published>2008-09-30T14:12:00.006+03:00</published><updated>2008-09-30T14:45:07.425+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java map containsKey equals hashCode'/><title type='text'>Java's Map.containsKey()</title><content type='html'>  Had a little problem recently with some complex keys in a map. The keys of my map were of this class:&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&lt;br /&gt;class Point{&lt;br /&gt;  private int x,y;&lt;br /&gt;  //...getters and setters&lt;br /&gt;  @Override&lt;br /&gt;  public String toString(){&lt;br /&gt;    return "("+x+","+y+")";&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;  The problem was that if i had a map containing an element with the key &lt;code&gt;(1,1)&lt;/code&gt; and I would try to check if that key is in the map like this: &lt;code&gt;myMap.containsKey( new Point(1,1) )&lt;/code&gt; this would not work. I tried to add the &lt;code&gt;equals&lt;/code&gt; method:&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&lt;br /&gt;class Point{&lt;br /&gt;  private int x,y;&lt;br /&gt;  //...getters and setters&lt;br /&gt;  @Override&lt;br /&gt;  public boolean equals(Object obj){&lt;br /&gt;    if(this == obj) return true; //exact same pointers&lt;br /&gt;    //check if same type&lt;br /&gt;    Point p = (Point)obj;&lt;br /&gt;    return (this.x==p.getX()&amp;amp;&amp;amp;this.y==p.getY());&lt;br /&gt;  }&lt;br /&gt;  //...toString() (see above)&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;  I thought this would surely solve the problem but it didn't. It seems that my equals method is not used at all. After some thoughts I realize that using equals would not be really efficient so they must be using something else. And of course, the most efficient mode of comparison is to use &lt;code&gt;hashCode()&lt;/code&gt;.&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&lt;br /&gt;class Point{&lt;br /&gt;  private int x,y;&lt;br /&gt;  //...getters and setters&lt;br /&gt;  //...equals() (see aboveve)&lt;br /&gt;  //...toString() (see above)&lt;br /&gt;  @Override&lt;br /&gt;  public int hashCode(){&lt;br /&gt;    return x&amp;lt;&amp;lt;16|y;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt; This is it! It now works and i can use &lt;code&gt;myMap.containsKey( new Point(1,1) )&lt;/code&gt;.  &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  My friend Bogdan Coanda suggested me &lt;code&gt;x&amp;lt;&amp;lt;16|y&lt;/code&gt; as being the fastest way to obtain an unique hash for the x,y combination. It's roughly equivalent with &lt;code&gt;x*(2**16)+y&lt;/code&gt; but faster as it doesn't care about carry on bits. This would give me unique values as long as my x and y stay below 16 bits numbers. This is a slight inconvenient but it does not affect me as my x and y are surely to stay below 16 bits.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-5114389829289708773?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/5114389829289708773/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=5114389829289708773' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5114389829289708773'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5114389829289708773'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/09/javas-mapcontainskey.html' title='Java&apos;s Map.containsKey()'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-1030429173410090694</id><published>2008-09-23T23:50:00.009+03:00</published><updated>2008-09-30T14:44:41.833+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hibernate inheritance java polymorphism generics'/><title type='text'>Generics and Hibernate polymorphism</title><content type='html'>I recently found myself in the position to have to map, using &lt;a href="http://hibernate.org/"&gt;Hibernate&lt;/a&gt; , a class family that had several common properties and a totally different one (among subclases) . The whole challange in that, was that i still had to keep a reference to that property in the abstract ancestor class (could have been an interface).&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To make sence, here is the class model:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;public abstract class Ancestor{&lt;br /&gt;&lt;/code&gt;&lt;/div&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&lt;div&gt;&lt;div&gt;  //...id property+getter and setter&lt;/div&gt;  private int commonProperty1;&lt;/div&gt;&lt;div&gt;  //... public getters and setters for common property&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  public abstract Object getDifferentProperty();&lt;/div&gt;&lt;div&gt;  public abstract void setDifferentProperty( Object prop );&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public class Child1 extends Ancestor{&lt;/div&gt;&lt;div&gt;  private Integer differentProperty;&lt;/div&gt;&lt;div&gt;  public Object getDifferentProperty(){&lt;/div&gt;&lt;div&gt;    return this.differentProperty;&lt;/div&gt;&lt;div&gt;  }&lt;/div&gt;&lt;div&gt;  public void setDifferentProperty( Object prop ){&lt;/div&gt;&lt;div&gt;    this.differentProperty = (Integer) prop;&lt;/div&gt;&lt;div&gt;  }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;public class Child2 extends Ancestor{&lt;/div&gt;&lt;div&gt;  private String differentProperty;&lt;/div&gt;&lt;div&gt;  public Object getDifferentProperty(){&lt;/div&gt;&lt;div&gt;    return this.differentProperty;&lt;/div&gt;&lt;div&gt;  }&lt;/div&gt;&lt;div&gt;  public void setDifferentProperty( Object prop ){&lt;/div&gt;&lt;div&gt;    this.differentProperty = (String) prop;&lt;/div&gt;&lt;div&gt;  }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;/code&gt;&lt;div&gt;&lt;br /&gt;Now, how you might have noticed, this is not such a good solution as the type cast in the setter is unsafe and the getter is useless unless you know to what to cast it. You could use reflection to make the cast safe or to check what's comming out of the getter, but still, there's a better solution. Let me show you.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;First, let's make the abstract ancestor take a generic as parameter.&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;public abstract class Ancestor&amp;lt;MyType&amp;gt;{&lt;br /&gt;&lt;/code&gt;&lt;/div&gt;&lt;div&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&lt;div&gt;  //...id property+getter and setter&lt;/div&gt;&lt;div&gt;  private int commonProperty1;&lt;/div&gt;&lt;div&gt;  //... public getters and setters for common property&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;  public abstract MyType getDifferentProperty();&lt;/div&gt;&lt;div&gt;  public abstract void setDifferentProperty(MyType prop );&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/code&gt;&lt;div&gt;&lt;br /&gt;Now, lets put that to use and use that in the children.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;public class Child1 extends Ancestor&amp;lt;Integer&amp;gt;{&lt;br /&gt;&lt;/code&gt;&lt;/div&gt;&lt;div&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&lt;div&gt;  private Integer differentProperty;&lt;/div&gt;&lt;div&gt;  public Integer getDifferentProperty(){&lt;/div&gt;&lt;div&gt;    return this.differentProperty;&lt;/div&gt;&lt;div&gt;  }&lt;/div&gt;&lt;div&gt;  public void setDifferentProperty( Integer prop ){&lt;/div&gt;&lt;div&gt;    this.differentProperty =  prop;&lt;/div&gt;&lt;div&gt;  }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/code&gt;&lt;div&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&lt;div&gt;public class Child2 extends Ancestor&amp;lt;String&amp;gt;{&lt;/div&gt;&lt;div&gt;  private String differentProperty;&lt;/div&gt;&lt;div&gt;  public String getDifferentProperty(){&lt;/div&gt;&lt;div&gt;    return this.differentProperty;&lt;/div&gt;&lt;div&gt;  }&lt;/div&gt;&lt;div&gt;  public void setDifferentProperty( String prop ){&lt;/div&gt;&lt;div&gt;    this.differentProperty = prop;&lt;/div&gt;&lt;div&gt;  }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/code&gt;&lt;div&gt;&lt;br /&gt;As you can see, now the child classes have setters and getters for the different property that ensure type safety and can still be used with calls that hit the ancestor class.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now, the trully beautifull thing for me was that this maps in Hibernate in no time:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&amp;lt;class name="Ancestor" table="ANCESTOR" abstract="true"&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;id name="id" type="string"&amp;gt;&lt;br /&gt;    &amp;lt;generator class="uuid.hex" /&amp;gt;&lt;br /&gt;  &amp;lt;/id&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;discriminator column="type" type="string"  /&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;property name="commonProperty1" column="comon_prop_1" type="interger" /&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;property name="commonProperty2" column="comon_prop_2" type="timestamp" /&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;subclass name="Child1" discriminator-value="C1"&amp;gt;&lt;br /&gt;    &amp;lt;join table="CHILD_1"&amp;gt;&lt;br /&gt;      &amp;lt;key column="id"&amp;gt;&lt;br /&gt;      &amp;lt;property name="differentProperty" type="integer" /&amp;gt;&lt;br /&gt;    &amp;lt;/join&amp;gt;&lt;br /&gt;  &amp;lt;/subclass&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;subclass name="Child2" discriminator-value="C2"&amp;gt;&lt;br /&gt;    &amp;lt;join table="CHILD_2"&amp;gt;&lt;br /&gt;      &amp;lt;key column="id"&amp;gt;&lt;br /&gt;      &amp;lt;property name="differentProperty" type="string" /&amp;gt;&lt;br /&gt;    &amp;lt;/join&amp;gt;&lt;br /&gt;  &amp;lt;/subclass&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/class&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Voila! Everithing will work as expected.&lt;/div&gt;&lt;/div&gt;&lt;/div&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/4134308587252322659-1030429173410090694?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/1030429173410090694/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=1030429173410090694' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/1030429173410090694'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/1030429173410090694'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/09/generics-and-hibernate-polymorphism.html' title='Generics and Hibernate polymorphism'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-8978011045693181359</id><published>2008-09-17T16:24:00.008+03:00</published><updated>2008-09-30T14:44:02.870+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='spring log logging log4j ioc'/><title type='text'>Spring, CommonsLogging and Log4J</title><content type='html'>Had some time lately to play with more than the usual default settings for log4j and found that Spring uses and supports Commons Logging to put a thin layer between the logging mechanism implementation and the logging call.&lt;br /&gt;&lt;br /&gt;For those that don't know about Commons Loggins, this provides a Log interface wich you use to log data, instead of calling the concrete implementation of Log4J for example. This way you can change from Log4J to any other supported loggin mechanism at any time. If in your project logging is important, you'll see the advantage of this.&lt;br /&gt;&lt;br /&gt;Anyway, what's more nice, is the way you can instantiate and inject the same logger in you beans. To instantiate the logger you create the bean&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt; org.springframework.beans.factory.config.CommonsLogFactoryBean&lt;/span&gt; in your application context like this:&lt;br /&gt;&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&amp;lt;bean id="mylog"&lt;br /&gt;class="org.springframework.beans.factory.config.CommonsLogFactoryBean"&amp;gt;&lt;br /&gt;    &amp;lt;property name="logName" value="mylog"&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;/code&gt;&lt;br /&gt;CommonsLogFactoryBean is a factory bean, wich means that when you reference it in another bean it won't return a&lt;span&gt;&lt;span&gt;n object of type org.springframework.be&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;ans.factory.config.CommonsLogFactoryBean , b&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;ut an object created by&lt;/span&gt; the factory (wich is preaty cool). Note that the factory will know by itself what type of logger you want to use based on the configurations you make. So when we place this config for log4j in web.xml it will khow that it must return a log4j logger.&lt;br /&gt;&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&amp;lt;context-param&amp;gt;&lt;/code&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;  &amp;lt;param-name&amp;gt;log4jConfigLocation&amp;lt;/param-name&amp;gt;&lt;/code&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;  &amp;lt;param-value&amp;gt;classpath:/config/log4j.xml&amp;lt;/param-value&amp;gt;&lt;/code&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&amp;lt;/context-param&amp;gt;&lt;/code&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&amp;lt;listener&amp;gt;&lt;/code&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;  &amp;lt;listener-class&amp;gt;org.springframework.web.util.Log4jConfigListener&amp;lt;/listener-class&amp;gt;&lt;/code&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&amp;lt;/listener&amp;gt;&lt;/code&gt;&lt;/code&gt;&lt;/code&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div&gt;One remark here that will save you some frustration: &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;you have to place the log4j listener before the Spring ContextLoaderListener or it won't configure right.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Ok, now we can inject &lt;span class="Apple-style-span" style="font-family: -webkit-monospace; font-size: 13px; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;mylog &lt;span class="Apple-style-span" style="font-family: Georgia; font-size: 16px; font-style: normal; font-weight: normal; "&gt;in any bean you want and start using it (remember, it's of type Log).&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In the last part of the blog I want to share with you some links about the configuration of log4j with an xml file. For a long time a properties file was used, but the xml is much more cool, an easier to understand. Actually, there are some stuff you can only configure with an xml.&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;log4j xml format: &lt;a href="http://wiki.apache.org/logging-log4j/Log4jXmlFormat"&gt;http://wiki.apache.org/logging-log4j/Log4jXmlFormat&lt;/a&gt;&lt;/li&gt;&lt;li&gt;an example with the usage of some appenders: &lt;a href="http://www.javaworld.com/javaforums/showflat.php?Cat=2&amp;amp;Board=TheoryPractice&amp;amp;Number=2396&amp;amp;page=0&amp;amp;view=collapsed&amp;amp;sb=11&amp;amp;o=&amp;amp;fpart=1"&gt; http://www.javaworld.com/javaforums/showflat.php?Cat=2&amp;amp;Board=TheoryPractice&amp;amp;Number=2396&amp;amp;page=0&amp;amp;view=collapsed&amp;amp;sb=11&amp;amp;o=&amp;amp;fpart=1&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-8978011045693181359?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/8978011045693181359/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=8978011045693181359' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/8978011045693181359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/8978011045693181359'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/09/spring-commonslogging-and-log4j.html' title='Spring, CommonsLogging and Log4J'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-8848708067978675588</id><published>2008-07-15T10:16:00.011+03:00</published><updated>2008-07-15T17:01:06.850+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='springmvc'/><category scheme='http://www.blogger.com/atom/ns#' term='mvc'/><category scheme='http://www.blogger.com/atom/ns#' term='spring'/><title type='text'>The choice (II)</title><content type='html'>I've finally made my decision about what to use for the presentation layer. &lt;a href="http://www.springframework.org/"&gt;Spring MVC&lt;/a&gt;. The reason behind my choice are the great level of configurability, the good quality of the documentation and samples, the vibrant community around it, the easiness of integration with &lt;a href="http://www.springframework.org/"&gt;Spring&lt;/a&gt;, &lt;a href="http://www.springframework.org/webflow"&gt;Spring Web Flow&lt;/a&gt;, &lt;a href="http://static.springframework.org/spring-ws/sites/1.5/"&gt;Spring Web Services&lt;/a&gt; and &lt;a href="http://static.springframework.org/spring-security/site/index.html"&gt;Spring Security&lt;/a&gt; one of my favorite project.&lt;br /&gt;&lt;br /&gt;The reason I previously discarded Spring MVC is because it seemed to require too much configuration for simple things. However, meanwhile I looked at the newly introduced &lt;a href="http://static.springframework.org/spring/docs/2.5.x/reference/mvc.html#mvc-coc"&gt;convention over configuration&lt;/a&gt; chapter in the Spring MVC documentation which describes how by sticking to established conventions and     having reasonable defaults you can &lt;span class="emphasis"&gt;&lt;em&gt;substantially&lt;/em&gt;&lt;/span&gt; cut     down on the amount of configuration that is required to set up handler     mappings, view resolvers, &lt;tt class="classname"&gt;ModelAndView&lt;/tt&gt; instances,     etc.&lt;br /&gt;&lt;br /&gt;Here's my setup of the project with wich I'm very happy. Makes things almost as easy as working with the defaults in a scripting language framework as &lt;a href="http://www.cakephp.org/"&gt;Cake PHP&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;First step is to start a normal project setup and write your deployment file (&lt;span style="font-style: italic;"&gt;web.xml&lt;/span&gt;) and your applicationContext files. I won't get into details as this is either common to any project or to specific for your needs. I'll just mention that you have to setup the Spring dispatcher servlet. This is where the http request will first get to, and will be forwarded to a controller capable of resolving it. I do this by placing these lines in &lt;span style="font-family:courier new;"&gt;/WEB-INF/web.xml&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&amp;lt;servlet&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;servlet-name&amp;gt;default&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;servlet-class&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;org.springframework.web.servlet.DispatcherServlet&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/servlet-class&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;load-on-startup&amp;gt;1&amp;lt;/load-on-startup&amp;gt;&lt;br /&gt;&amp;lt;/servlet&amp;gt;&lt;br /&gt;&amp;lt;servlet-mapping&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;servlet-name&amp;gt;default&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;&amp;lt;/servlet-mapping&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This instantiates a dispatcher that listens to all requested urls and tries to find a controller for them. If you want to have different dispatchers for different type of urls you can adjust the url-pattern. But again, this is about convention, and you will almost always need a single dispatcher.&lt;br /&gt;&lt;br /&gt;The next step is to set up a handler mapping in &lt;span style="font-family:courier new;"&gt;/WEB-INF/default-servlet.xml&lt;/span&gt; (or a matching application context in case you didn't named your dispatcher servlet &lt;span style="font-family:courier new;"&gt;default&lt;/span&gt;). This is actually the component that tries to find for the dispatcher a controller suitable for a certain url. There are many types of handlers, including ones that expect a manual mapping of the url to the controller, or you can write your own handler, but the one i use is:&lt;br /&gt;&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&amp;lt;bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/&amp;gt;&lt;/code&gt;&lt;br /&gt;This will instantiate one of the simplest handlers. This will take the url, strip the prefix and the suffix and will search for a bean controller that matches that name. For example, if the requested url is: &lt;span style="font-family:courier new;"&gt;www.mydomain.com/users/all&lt;/span&gt;, this will search for a bean called: &lt;span style="font-family:courier new;"&gt;usersController&lt;/span&gt;. Preaty simple, right? You can now provide the controller:&lt;br /&gt;&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&amp;lt;bean name="usersController" class="com.mydomain.web.controllers.UsersController" /&amp;gt;&lt;/code&gt;&lt;br /&gt;This handler will suffice for most situations. You can read more about it from the &lt;a href="http://static.springframework.org/spring/docs/2.5.x/reference/mvc.html#mvc-coc-ccnhm"&gt;spring documentation&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Ok, so we reached the point where  we actually have to handle the http request. A controller's job is to do exactly that. Now, there are several types of controllers each particularly good in a situation, but the one I think is the most useful is the &lt;span style="font-family:courier new;"&gt;MultiActionController&lt;/span&gt;. I find it that usefull because it can bundle the code for several requests in a single class. That's particullary useful when you have tasks concerning the same problem. For example you can treat the urls &lt;span style="font-family:courier new;"&gt;mydomain.com/users/add&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;mydomain.com/users/delete&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;mydomain.com/users/show&lt;/span&gt; etc. in the same controller.&lt;br /&gt;&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;public class UsersController extends MultiActionController {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;private UserDao userdao;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;public ModelAndView all(HttpServletRequest request, HttpServletResponse response) throws Exception {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;user&amp;gt; usrs = userdao.getAllUsers();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ModelAndView mv = new ModelAndView();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mv.addObject("users",usrs);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return mv;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;public void setUserDao( UserDao userdao ){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.userdao = userdao;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;Now that we have the multiaction controller we must have a method of deciding which method will be called and when. This is the job of a Method Name Resolver. To keep things simple we will use the&lt;span style="font-family:courier new;"&gt; org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver&lt;/span&gt;.&lt;br /&gt;This takes the url immediately after the controller name part and tries to match it to a method in that controller. Basically the, previously used  &lt;span style="font-family:courier new;"&gt;www.mydomain.com/users/all&lt;/span&gt; url will be matched to the &lt;span style="font-family:courier new;"&gt;all&lt;/span&gt; method in the &lt;span style="font-family:courier new;"&gt;usersController &lt;/span&gt;bean. The method name resolver would have to be specified as the &lt;span style="font-family:courier new;"&gt;methodNameResolver &lt;/span&gt;property of the multiaction controller, but fortunately if we don't specify any, Spring will provide exactly this one for us.&lt;br /&gt;&lt;br /&gt;One last note: in order for a method of a multiaction controller to be considered, it must have at lease 2 parameters: &lt;span style="font-family:courier new;"&gt;HttpServletRequest request, HttpServletResponse response&lt;/span&gt;. You can read more about what parameters the methods can take on the &lt;a href="http://static.springframework.org/spring/docs/2.5.x/reference/mvc.html#mvc-controller-multiaction"&gt;spring documentation&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Ok, we're done with the controller. Let's go to the view. As you maybe have noticed i haven't provided any view name when i instantiated the &lt;span style="font-family:courier new;"&gt;ModelAndView&lt;/span&gt;. This might look at least weird. The fact is that I use another configuration trick. I use a bean instantiated by Spring which finds a name for the unprovided view names based on the url. The bean is: &lt;span style="font-family:courier new;"&gt;org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator&lt;/span&gt; and as I said, it's instantiaded by Spring so you don't have to do anything about it. The name it provides is by stripping the prefix and the sufix of the url. So in our case, from the &lt;span style="font-family:courier new;"&gt;www.mydomain.com/users/all&lt;/span&gt; url we would get the &lt;span style="font-family:courier new;"&gt;users/all&lt;/span&gt; name.&lt;br /&gt;&lt;br /&gt;We're almost there. One thing left to do: the view resolver. I used &lt;a href="http://velocity.apache.org/"&gt;Velocity&lt;/a&gt; for my sample but you can use whatever view technology you want. Here is my setup:&lt;br /&gt;&lt;br /&gt;&lt;code style="display: block; background-color: rgb(238, 238, 238);"&gt;&amp;lt;bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;property name="configLocation"&amp;gt;&amp;lt;value&amp;gt;/WEB-INF/velocity.properties&amp;lt;/value&amp;gt;&amp;lt;/property&amp;gt;        &lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&amp;lt;bean id="velocityViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;property name="viewClass" value="org.springframework.web.servlet.view.velocity.VelocityView"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;property name="prefix" value="/WEB-INF/views/"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;property name="suffix" value=".vm"/&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;  &lt;/code&gt;&lt;br /&gt;So, now that we're done, let's see what have we accomplished. We have a basic Spring MVC setup which by using different convention tricks provides a straight forward way of writing your web layer, without requiring you to write a ton of xml for each controller. A url in the form: &lt;span style="font-family:courier new;"&gt;www.mydomain.com/users/all&lt;/span&gt; will be sent to a bean with the name &lt;span style="font-family: courier new;"&gt;usersController&lt;/span&gt;, to it's &lt;span style="font-family: courier new;"&gt;all&lt;/span&gt; method. This in turn will perform any required processing and send the model to the &lt;span style="font-family: courier new;"&gt;/WEB-INF/view/users/all.vm&lt;/span&gt; velocity template for rendering.&lt;span style="font-family:courier new;"&gt; &lt;/span&gt;For any new controller we will only have to vrite the xml than instantiates it. It's a great way to speed up your developing process by cutting down significantly the required configuration xml, and providing an intuitive&lt;span style="font-family:courier new;"&gt; &lt;/span&gt;url handling chain.&lt;span style="font-family:courier new;"&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/4134308587252322659-8848708067978675588?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/8848708067978675588/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=8848708067978675588' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/8848708067978675588'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/8848708067978675588'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/07/choice-ii.html' title='The choice (II)'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-1091165727769601734</id><published>2008-06-20T20:08:00.006+03:00</published><updated>2008-07-05T04:29:36.047+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='grub'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='windows'/><category scheme='http://www.blogger.com/atom/ns#' term='dual-boot'/><category scheme='http://www.blogger.com/atom/ns#' term='ubuntu'/><title type='text'>Do you want to uninstall your OS?</title><content type='html'>I recently installed the new &lt;a href="http://www.ubuntu.com/"&gt;Ubuntu&lt;/a&gt; 8.04 LTS to check out what's new in the Linux world. I had a few months try a while ago with the Ubunutu 7, but eventually rolled back to XP because I was missing &lt;a href="http://www.adobe.com/products/photoshop/index.html"&gt;Photoshop&lt;/a&gt; to damn much (that thing is addictive) and editing 10000 x 10000 pixels pictures in virtual machine is a killer.&lt;br /&gt;&lt;br /&gt;What i first noticed was the "Install inside Windows" and checked it thinking that that's just a fancy way to say "dual operating systems". Everything went well and as I dived in the new Ubuntu I was nicely impressed by the progress done in bug fixing, look improvements and easyness of use. Now, I think, they really have a competitive alternative to windows. You can configure almost everything in a Windows fashion and the Synaptic installer is the chery on the cake (as always). Plus, wine now supports Photoshop CS2 really well and even &lt;a href="http://www.apple.com/itunes/"&gt;iTunes&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;But enough about that, I'll decide if to give linux another go later. I was telling about the "install inside windows" option. The big surprise was when i restarted back to xp and noticed that i have all my drives intact. The only difference was that my D: drive was occupied with the ammount i indicated to Ubuntu to use. The bigger surprise, was when i navigated through the new ubuntu folder and found the magic "Uninstall-Ubuntu.exe". Preaty cool huh? I think it's a brilliant move, allowing people to check out Ubuntu much more easy, without having the worry of that headake uninstall process (with the repartitioning and removing of grub, etc). And as I said, the new features, or perhaps improvements, are to be checked out.&lt;br /&gt;&lt;br /&gt;Go go Linux group, go! (even thow i almost alwasy used windows beacuse of different software requirements, i always found something phrenetic about using linux).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4134308587252322659-1091165727769601734?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/1091165727769601734/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=1091165727769601734' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/1091165727769601734'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/1091165727769601734'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/06/do-you-want-to-uninstall-your-os.html' title='Do you want to uninstall your OS?'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4134308587252322659.post-5345523624829481592</id><published>2008-06-06T00:00:00.001+03:00</published><updated>2008-07-05T04:30:35.346+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tapestry'/><category scheme='http://www.blogger.com/atom/ns#' term='springmvc'/><category scheme='http://www.blogger.com/atom/ns#' term='mvc'/><category scheme='http://www.blogger.com/atom/ns#' term='stripes'/><category scheme='http://www.blogger.com/atom/ns#' term='spring'/><category scheme='http://www.blogger.com/atom/ns#' term='click'/><category scheme='http://www.blogger.com/atom/ns#' term='struts'/><title type='text'>The choice (I)</title><content type='html'>As I'm at the begining of a fresh new web project I get to choose what frameworks I'm going to try next from this &lt;span style="font-weight: bold;"&gt;huge &lt;/span&gt;set of options in the &lt;span style="font-style: italic;"&gt;Java Universe&lt;/span&gt;. As much as this promises to be a mess, I keep telling myself this is actually a great opportunity to &lt;span style="font-weight: bold;"&gt;move forward&lt;/span&gt;, discover new, better ways to do things.&lt;br /&gt;&lt;br /&gt;Some things i have clear:&lt;br /&gt;&lt;ul&gt;&lt;li&gt; I'll use &lt;a href="http://springframework.org/"&gt;Spring&lt;/a&gt; as my &lt;a href="http://martinfowler.com/articles/injection.html"&gt;IoC&lt;/a&gt; container. It seems by far the most appreciated of it's kind. The thing I like the most is that it stays out of the way. You get to decide how much of it will you use.&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.hibernate.org/"&gt;Hibernate&lt;/a&gt; will be my ORM tool. It's complex and shiny and scarily big, but the size of my project says I do need an ORM so why not get what offers me most functionality. I'll worry about optimization later.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;However, when it get to the presentation layer it gets crazy. Until now I've read dozens of "x vs y" articles, tens of "what my framework can do" screencasts and still haven't decided. Have you seen the choice range? Let me spill a few for you:&lt;br /&gt;&lt;br /&gt;&lt;table style="width: 649px; height: 332px;" class="confluenceTable"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="confluenceTd"&gt;Echo&lt;/td&gt; &lt;td class="confluenceTd"&gt;Cocoon&lt;/td&gt; &lt;td class="confluenceTd"&gt;Millstone&lt;/td&gt; &lt;td class="confluenceTd"&gt;OXF&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;Struts&lt;/td&gt; &lt;td class="confluenceTd"&gt;SOFIA&lt;/td&gt; &lt;td class="confluenceTd"&gt;Tapestry&lt;/td&gt; &lt;td class="confluenceTd"&gt;WebWork&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;RIFE&lt;/td&gt; &lt;td class="confluenceTd"&gt;Spring MVC&lt;/td&gt; &lt;td class="confluenceTd"&gt;Canyamo&lt;/td&gt; &lt;td class="confluenceTd"&gt;Maverick&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;JPublish&lt;/td&gt; &lt;td class="confluenceTd"&gt;JATO&lt;/td&gt; &lt;td class="confluenceTd"&gt;Folium&lt;/td&gt; &lt;td class="confluenceTd"&gt;Jucas&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;Verge&lt;/td&gt; &lt;td class="confluenceTd"&gt;Niggle&lt;/td&gt; &lt;td class="confluenceTd"&gt;Bishop&lt;/td&gt; &lt;td class="confluenceTd"&gt;Barracuda&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;Action Framework&lt;/td&gt; &lt;td class="confluenceTd"&gt;Shocks&lt;/td&gt; &lt;td class="confluenceTd"&gt;TeaServlet&lt;/td&gt; &lt;td class="confluenceTd"&gt;wingS&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;Expresso&lt;/td&gt; &lt;td class="confluenceTd"&gt;Bento&lt;/td&gt; &lt;td class="confluenceTd"&gt;jStatemachine&lt;/td&gt; &lt;td class="confluenceTd"&gt;jZonic&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;OpenEmcee&lt;/td&gt; &lt;td class="confluenceTd"&gt;Turbine&lt;/td&gt; &lt;td class="confluenceTd"&gt;Scope&lt;/td&gt; &lt;td class="confluenceTd"&gt;Warfare&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;JWAA&lt;/td&gt; &lt;td class="confluenceTd"&gt;Jaffa&lt;/td&gt; &lt;td class="confluenceTd"&gt;Jacquard&lt;/td&gt; &lt;td class="confluenceTd"&gt;Macaw&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;Smile&lt;/td&gt; &lt;td class="confluenceTd"&gt;MyFaces&lt;/td&gt; &lt;td class="confluenceTd"&gt;Chiba&lt;/td&gt; &lt;td class="confluenceTd"&gt;JBanana&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;Jeenius&lt;/td&gt; &lt;td class="confluenceTd"&gt;JWarp&lt;/td&gt; &lt;td class="confluenceTd"&gt;Genie&lt;/td&gt; &lt;td class="confluenceTd"&gt;Melati&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;Dovetail&lt;/td&gt; &lt;td class="confluenceTd"&gt;Cameleon&lt;/td&gt; &lt;td class="confluenceTd"&gt;JFormular&lt;/td&gt; &lt;td class="confluenceTd"&gt;Xoplon&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;Japple&lt;/td&gt; &lt;td class="confluenceTd"&gt;Helma&lt;/td&gt; &lt;td class="confluenceTd"&gt;Dinamica&lt;/td&gt; &lt;td class="confluenceTd"&gt;WebOnSwing&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;Nacho&lt;/td&gt; &lt;td class="confluenceTd"&gt;Cassandra&lt;/td&gt; &lt;td class="confluenceTd"&gt;Baritus&lt;/td&gt; &lt;td class="confluenceTd"&gt;Stripes&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="confluenceTd"&gt;Click&lt;/td&gt; &lt;td class="confluenceTd"&gt;GWT&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;Easy right? The simple truth is that there are to many damn choices and from all these there is no "best framework". Certainly some of them more complex, more documented, scale better, have a smaller learning curve, but in the end it's all about &lt;span style="font-weight: bold;"&gt;taste&lt;/span&gt;. You heard me: taste. The discussion around &lt;a href="http://www.oreillynet.com/onjava/blog/2006/06/isnt_rails_supposed_to_change.html"&gt;this article&lt;/a&gt; of &lt;a href="http://www.oreillynet.com/pub/au/1738"&gt;Tim O'Brien&lt;/a&gt;&lt;span class="ISI_IGNORE"&gt;  made me realize that. Some prefer to do things in one way some in others. And for them, doing stuff just as their brain patterns out the problem makes it the best possible choice.&lt;br /&gt;&lt;br /&gt;But what &lt;span style="font-weight: bold;"&gt;I'm &lt;/span&gt;looking for? Well, coming from a long experience with PHP and &lt;a href="http://www.cakephp.org/"&gt;CakePHP&lt;/a&gt;, what I noticed first is the difficulty to configure for most of them.  All the  great features and power come with a heavy price. In order to display a page you have to write a ton of xml or other stuff that in most cases is plain redundant. Or if not, you have to invest much more time in finding &lt;span style="font-style: italic;"&gt;secret ways&lt;/span&gt; to avoid that. I would surely want to see more &lt;a href="http://en.wikipedia.org/wiki/Convention_over_Configuration"&gt;Convention over Configuration&lt;/a&gt; in Java world. For now it seems like most of the frameworks were made for control freaks.&lt;br /&gt;&lt;br /&gt;Let's list the candidates i have so far:&lt;br /&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://struts.apache.org/2.x/index.html"&gt;Struts 2&lt;/a&gt; - this is a more elegant, complete, rewrite of the old Struts framework which even with serious flaws was once the most used framework of its kind. I would choose this because I could benefit from my past knowledge with the old Struts.  Plus, being under the Apache umbrella is always a good sign.&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.springframework.org/"&gt;SpringMVC &lt;/a&gt;- this would get me nice integration with Spring, SpringWeb and &lt;a href="http://static.springframework.org/spring-security/site/index.html"&gt;SpringSecurity&lt;/a&gt;. It's extremely configurable, but it requires tons of xml for things that should be direct.&lt;/li&gt;&lt;li&gt;&lt;a href="http://click.sourceforge.net/"&gt;Click&lt;/a&gt; - this seems one of the lightest, but I'm thinking it's maybe too light. It contains only a few packages.&lt;/li&gt;&lt;li&gt;&lt;a href="http://tapestry.apache.org/"&gt;Tapestry&lt;/a&gt; - looks kind of nice and less heavy but everybody is complaining that it has a huge learning curve.&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.stripesframework.org/display/stripes/Home"&gt;Stripes&lt;/a&gt; - heard a great deal about this but it might be just programmers bloating. However i got to investigate it further. If what they say in the slogan is at least 50% true it might be what I'm looking for: &lt;span style="font-style: italic;"&gt;Stripes aims to provide an experience similar to owning Apple hardware, Sony TVs and luxury German cars (without the price premium); things just work, they feel &lt;/span&gt;&lt;em style="font-style: italic;"&gt;right&lt;/em&gt;&lt;span style="font-style: italic;"&gt; and every now and again you get that "oh, it does that too?  awesome!" feeling.&lt;/span&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/4134308587252322659-5345523624829481592?l=cristianvrabie.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cristianvrabie.blogspot.com/feeds/5345523624829481592/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4134308587252322659&amp;postID=5345523624829481592' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5345523624829481592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4134308587252322659/posts/default/5345523624829481592'/><link rel='alternate' type='text/html' href='http://cristianvrabie.blogspot.com/2008/06/choice-i.html' title='The choice (I)'/><author><name>Cristian Vrabie</name><uri>http://www.blogger.com/profile/18060414800660320002</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_hQod6j7fOTU/TMA7KL3JNKI/AAAAAAAAAiM/Uadu94Q7ySo/s1600-R/32542_455489634255_824409255_6064115_6912331_n.jpg'/></author><thr:total>0</thr:total></entry></feed>
