<?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-8709325616717239681</id><updated>2011-08-25T10:54:32.827+10:00</updated><category term='ruby'/><category term='Agile'/><category term='gem'/><category term='rails'/><category term='HIbernate'/><category term='maven'/><category term='tomcat'/><category term='eclipse'/><category term='Spring'/><category term='Java'/><category term='Rest'/><category term='Style'/><category term='rake'/><category term='netbeans'/><title type='text'>Bandaid Programming</title><subtitle type='html'>Tips and tricks and hacks for software craftsmen.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>18</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-975061976434041545</id><published>2010-04-07T10:27:00.000+10:00</published><updated>2010-04-07T10:27:10.386+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>Rails / Ruby DateTime Stuff</title><content type='html'>A great blog entry: http://anandmuranal.wordpress.com/2007/12/12/formating-date-time-in-rails/&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-975061976434041545?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/975061976434041545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=975061976434041545' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/975061976434041545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/975061976434041545'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2010/04/rails-ruby-datetime-stuff.html' title='Rails / Ruby DateTime Stuff'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-6125616799762850761</id><published>2010-02-02T15:38:00.000+11:00</published><updated>2010-02-02T15:38:16.276+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><category scheme='http://www.blogger.com/atom/ns#' term='gem'/><title type='text'>Rails update a gem to an older version</title><content type='html'>You want say rack version 1.0.1 but the latest version is rack 1.1 and it's installed on your machine:&lt;br /&gt;&lt;br /&gt;gem install [gem name] --version [version number]&lt;br /&gt;&lt;br /&gt;For example: &lt;br /&gt;gem install rack --version 1.0.1&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-6125616799762850761?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/6125616799762850761/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=6125616799762850761' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/6125616799762850761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/6125616799762850761'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2010/02/rails-update-gem-to-older-version.html' title='Rails update a gem to an older version'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-5939578995336097749</id><published>2009-11-20T12:39:00.002+11:00</published><updated>2009-11-20T13:20:35.617+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>Getting Threads in Rails</title><content type='html'>So you want threads in rails? Add the following 2 lines to your production.rb file:&lt;br /&gt;&lt;br /&gt;config.threadsafe!&lt;br /&gt;config.eager_load_paths &amp;lt;&amp;lt; "#{RAILS_ROOT}/lib"&lt;br /&gt;&lt;br /&gt;For more reading, checkout: &lt;a href="http://m.onkey.org/2008/10/23/thread-safety-for-your-rails"&gt;http://m.onkey.org/2008/10/23/thread-safety-for-your-rails&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-5939578995336097749?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/5939578995336097749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=5939578995336097749' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/5939578995336097749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/5939578995336097749'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2009/11/threadsafe-rails.html' title='Getting Threads in Rails'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-2043504911965657857</id><published>2009-10-27T14:09:00.001+11:00</published><updated>2009-10-27T14:11:40.098+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>Rails: Unpacking your gems into vendor/gems</title><content type='html'>Okay you have your marvelous gem but want to put it into the vendor directly.&lt;br /&gt;&lt;br /&gt;No worries. In this example I will be working with the "marc (0.3.0)" gem.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Edit the environment.rb file and under the "Rails::Initializer.run do |config|" put the following line: config.gem 'marc'&lt;/li&gt;&lt;li&gt;Next "rake gems:unpack GEM=marc" where GEM=gem_name - don't worry about the version number.&lt;/li&gt;&lt;/ol&gt;All done. You should have a new directory under vendor/gems/gem_name.&lt;br /&gt;&lt;br /&gt;Troubleshooting. If this doesn't quite work, you might want to try:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Create the gems directory under vendor yourself&lt;/li&gt;&lt;li&gt;It may complain that it lacks the specification file. If so go to the vendor/gems/gem_name directory and run: gem specification gem_name &amp;gt; .specification&lt;/li&gt;&lt;/ul&gt;If this still doesn't work ... then google or bing yourself to death.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-2043504911965657857?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/2043504911965657857/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=2043504911965657857' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/2043504911965657857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/2043504911965657857'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2009/10/rails-unpacking-your-gems-into.html' title='Rails: Unpacking your gems into vendor/gems'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-7744334401019129848</id><published>2009-10-26T11:17:00.000+11:00</published><updated>2009-10-26T11:17:10.153+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>Viewing RDoc for installed gems</title><content type='html'>Pretty simple:&lt;br /&gt;&lt;br /&gt;gem server&lt;br /&gt;&lt;br /&gt;It's then available on localhost:8808&lt;br /&gt;&lt;br /&gt;Pretty cool. It's like having available doc for JAR files. Sort of.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-7744334401019129848?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/7744334401019129848/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=7744334401019129848' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/7744334401019129848'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/7744334401019129848'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2009/10/viewing-rdoc-for-installed-gems.html' title='Viewing RDoc for installed gems'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-2041661441557825880</id><published>2009-10-21T14:30:00.000+11:00</published><updated>2009-10-21T14:30:36.669+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>Metaprogramming in Ruby is awesome</title><content type='html'>Well I had to override the behaviour of the Oracle Enhanced Adapter when creating sequence names. By default it creates them as "tablename_seq" where our database was "sq_tablename".&lt;br /&gt;&lt;br /&gt;After reading &lt;a href="http://liamgraham.wordpress.com/2008/07/01/fixing-rails-bizarre-approach-to-creating-oracle-sequences/"&gt;this&lt;/a&gt; post. I made my change and placed it under the config/initializers directory.&lt;br /&gt;&lt;br /&gt;But the concept of metaprogramming in Ruby is really intriguing.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-2041661441557825880?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/2041661441557825880/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=2041661441557825880' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/2041661441557825880'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/2041661441557825880'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2009/10/metaprogramming-in-ruby-is-awesome.html' title='Metaprogramming in Ruby is awesome'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-427446619139642314</id><published>2009-10-19T12:04:00.003+11:00</published><updated>2010-02-18T11:21:55.914+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><category scheme='http://www.blogger.com/atom/ns#' term='netbeans'/><title type='text'>Netbeans Ruby Oracle OCI Mac Problem</title><content type='html'>Okay. You are using netbeans and connecting to Oracle. You have installed the Oracle Instant Client and have set the DYLD_LIBRARY_PATH='&lt;path_to&gt;/instantclient' in your shell. All is well if you run your rails app from the command line. &lt;br /&gt;&lt;br /&gt;Right. &lt;br /&gt;&lt;br /&gt;But when you run it through Netbeans you get the error telling you to some effect:&lt;br /&gt;&lt;br /&gt;"ERROR: ActiveRecord oracle_enhanced adapter could not load ruby-oci8 library. Please install ruby-oci8 library or gem."&lt;br /&gt;&lt;br /&gt;The explanation is that for some reason Netbeans on the mac does not pick up the settings set say in your .bashrc file. The easiest solution is to add the line:&lt;br /&gt;&lt;br /&gt;"source ~/.bashrc" to your netbeans startup script.&lt;br /&gt;&lt;br /&gt;Now Netbeans will pick up all your paths.&lt;/path_to&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-427446619139642314?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/427446619139642314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=427446619139642314' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/427446619139642314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/427446619139642314'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2009/10/netbeans-ruby-oracle-oci-mac-problem.html' title='Netbeans Ruby Oracle OCI Mac Problem'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-1827103007462136480</id><published>2009-09-03T16:19:00.004+10:00</published><updated>2009-09-03T16:37:28.154+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><category scheme='http://www.blogger.com/atom/ns#' term='rake'/><title type='text'>Excuting Rails Unit Tests without blowing away your database</title><content type='html'>Okay ...&lt;br /&gt;&lt;br /&gt;I have my nice shiny rails app. I have written a heap of tests. But I don't want to blow the TEST database away each time I execute rake test:units.&lt;br /&gt;&lt;br /&gt;Be aware when you use say "rake test" it calls "rake db:test:prepare" which essentially blows away your test database and reloads it. &lt;br /&gt;&lt;br /&gt;There are a couple of approaches:&lt;br /&gt;&lt;br /&gt;One: Run the test through Ruby and not Rake&lt;br /&gt;-------------------------------------------&lt;br /&gt;Run your test: ruby -I test test/unit/my_test.rb&lt;br /&gt;&lt;br /&gt;The -I flag ensures that the file &lt;your-app&gt;/test/test_helper.rb is loaded.&lt;br /&gt; &lt;br /&gt;You could then write your own rake task to run all the unit tests.&lt;br /&gt;&lt;br /&gt;Two: Write your own rake task to use instead of rake test:units&lt;br /&gt;---------------------------------------------------------------&lt;br /&gt;In this approach. The aim is to ensure that the "db:test:prepare" task is not called. You do this by clearing the prerequisites for "rake test:units"&lt;br /&gt;&lt;br /&gt;i.e.&lt;br /&gt;  task :test_units do&lt;br /&gt;    Rake::Task['test:units'].prerequisites.clear&lt;br /&gt;    Rake::Task['test:units'].invoke&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;You then invoke your task: "rake test_units"&lt;br /&gt;Also call "rake -T" to see your task listed.&lt;br /&gt;&lt;br /&gt;For more details:&lt;br /&gt;&lt;a href="http://paulbarry.com/articles/2009/04/20/the-busy-rails-developers-intro-to-rake"&gt;Check out Paul Barry's post&lt;/a&gt;&lt;br /&gt;&lt;a href="http://blog.jayfields.com/2006/06/ruby-on-rails-unit-tests.html"&gt;Jay Field's post&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-1827103007462136480?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/1827103007462136480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=1827103007462136480' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/1827103007462136480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/1827103007462136480'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2009/09/excuting-rails-unit-tests-without.html' title='Excuting Rails Unit Tests without blowing away your database'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-6645896046643725759</id><published>2009-03-31T15:02:00.002+11:00</published><updated>2009-03-31T15:04:11.589+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>Rails partials are awesome</title><content type='html'>This is a great blog post on partials. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://addictedtonew.com/archives/149/a-bit-on-rails-partials/"&gt;http://addictedtonew.com/archives/149/a-bit-on-rails-partials/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Partials are so stealth!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-6645896046643725759?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/6645896046643725759/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=6645896046643725759' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/6645896046643725759'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/6645896046643725759'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2009/03/rails-partials-are-awesome.html' title='Rails partials are awesome'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-5844652182951132379</id><published>2008-11-07T10:00:00.007+11:00</published><updated>2008-11-07T10:23:10.766+11:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>Rails 2.0 ActionMailer and SMTP email</title><content type='html'>Okay, you want to use ActionaMailer in Rails to send smtp mail. First some useful links:&lt;br /&gt;&lt;a href="http://apidock.com/rails/ActionMailer/Base"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://wiki.rubyonrails.org/rails/pages/HowToSendEmailsWithActionMailer"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.jonathansng.com/ruby-on-rails/rails-send-email-tutorial/"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;1 - Create a new file in the config/initializers/action_mailer.rb (The file can be called anything)&lt;br /&gt;&lt;br /&gt;2 - Place the following settings in it:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;ActionMailer::Base.delivery_method = :smtp&lt;br /&gt;ActionMailer::Base.perform_deliveries = true&lt;br /&gt;ActionMailer::Base.default_charset = "utf-8"&lt;br /&gt;ActionMailer::Base.raise_delivery_errors = true&lt;br /&gt;&lt;br /&gt;ActionMailer::Base.smtp_settings = {&lt;br /&gt;  :address =&gt; "your.smtp.server",&lt;br /&gt;  :port =&gt; 25,&lt;br /&gt;  :domain =&gt; "your.domain",&lt;br /&gt;  :user_name =&gt; "username",&lt;br /&gt;  :password =&gt; "password"&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You should be able to send SMTP mail. Go and read the above doc about using ActionMailer to create the email and send it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-5844652182951132379?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/5844652182951132379/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=5844652182951132379' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/5844652182951132379'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/5844652182951132379'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2008/11/rails-20-actionmailer-and-smtp-email.html' title='Rails 2.0 ActionMailer and SMTP email'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-7251029669400722021</id><published>2008-08-19T22:13:00.003+10:00</published><updated>2008-08-19T22:28:44.355+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>On the Rails Hype Cycle</title><content type='html'>I found this &lt;a href="http://www.techcrunch.com/2008/08/18/where-are-we-in-the-hype-cycle/"&gt;interesting graph&lt;/a&gt; on a blog entry about the Technology Hype Cycle. &lt;br /&gt;&lt;br /&gt;The diagram is interesting and made me think about my current Rails experience. Each time I code and do something, I really enjoy myself. A side question is ... am I allowed to enjoy myself whilst coding? Past experience in most Java frameworks has been defined more by pain than "enjoyment". I digress.&lt;br /&gt;&lt;br /&gt;Two days ago a new rails book I ordered from Amazon arrived(&lt;a href="http://www.amazon.com/Simply-Rails-2-Patrick-Lenz/dp/0980455200/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1219148753&amp;sr=8-1"&gt;Simply Rails 2 - by Patrick Lenz&lt;/a&gt;). I was frothing with anticipation. Even though I have only read the first few chapters and I haven't really learned anything that I didn't already know, yet I am still frothing. &lt;br /&gt;&lt;br /&gt;I think that I am still on the way to reach the peak of Inflated Expectations. I just hope that when the Trough of Disillusionment sets in that it won't be so bad. I guess live it up now.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-7251029669400722021?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/7251029669400722021/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=7251029669400722021' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/7251029669400722021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/7251029669400722021'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2008/08/on-rails-hype-cycle.html' title='On the Rails Hype Cycle'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-590869252841093568</id><published>2008-08-11T20:31:00.000+10:00</published><updated>2008-08-11T23:03:30.264+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>I am really enjoying Rails!</title><content type='html'>Well for a freelance project, I decided to use Ruby On Rails. I have heard the hype. Seen developers at work use it ... blah etc. &lt;br /&gt;&lt;br /&gt;After mixing tutorials for Rails 1.2 and Rails 2.0 (There are not that many for 2.0) I actually managed to code something quite easily. I was quite surprised. I think that the scaffolding thing is just awesome. I even "rewrote" my small app a few times as I learnt to do it better. I think the telling thing was that I wrote the app in Rails 2.1.0. Once I uploaded it to my server I was having it hosted on, I realised that they only offered Rails 2.0.2. I rewrote it again. I even managed to figure out how to various rails versions on my local machine and use the version I wanted. Very cool.&lt;br /&gt;&lt;br /&gt;Some helpful Rails 2.0 tutorials:&lt;br /&gt;&lt;a href="http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I did this all on my mac. I installed &lt;a href="http://www.mamp.info/en/index.php"&gt;Mamp&lt;/a&gt; to get MySql and I eventually settled on textmate as editor as my machine just did not have enough grunt to use Eclipse.&lt;br /&gt;&lt;br /&gt;The really great thing is that I am enjoying it. There are some things that have been frustrating, but this has been way easier to learn than say Spring/Hibernate combo.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-590869252841093568?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/590869252841093568/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=590869252841093568' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/590869252841093568'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/590869252841093568'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2008/08/i-am-really-enjoying-rails.html' title='I am really enjoying Rails!'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-5425178413484300767</id><published>2008-05-09T14:49:00.000+10:00</published><updated>2008-08-11T23:05:37.723+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Rest'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Spring'/><title type='text'>REST in Spring without using Spring Webservices</title><content type='html'>I quite like using Spring. Especially when using the Spring/Hibernate combo.&lt;br /&gt;&lt;br /&gt;About a year ago I started using Spring for a whole heap of REST webservices I was writing.  In the process I found it surprisingly easy. Various other colleagues experimented with RESTLET (http://www.restlet.org/) and Jersey (https://jersey.dev.java.net/). But as I wanted to use Hibernate easily and I was using Spring MVC to build the client component of the project I was working on, so I used Spring MVC to build the services. Pretty simple. (Even though I refer to Spring 2.5 in the pom file, I am not using the features of 2.5.)&lt;br /&gt;&lt;br /&gt;Here's an example:&lt;br /&gt;&lt;br /&gt;I have created a simple webapp using maven. The webapp is called rest-webapp. I have created a stupid service that retrieves the name of an evil programmer.&lt;br /&gt;&lt;br /&gt;This means that the request would look like:&lt;br /&gt;http://localhost:8080/rest-webapp/evil/programmers/1&lt;br /&gt;&lt;br /&gt;and this would return:&lt;br /&gt;&lt;response&gt;Dr Evil&lt;/response&gt;&lt;br /&gt;&lt;br /&gt;I wrote a simple class that does this and also returns a 404 error if the request for tne evil programmer does not exist.&lt;br /&gt;&lt;br /&gt;This means that the request would look like:&lt;br /&gt;http://localhost:8080/rest-webapp/evil/programmers/6&lt;br /&gt;&lt;br /&gt;would return a 404 error with the message:  &lt;span style="font-weight: bold;font-size:100%;" &gt;HTTP Status 404 - This evil programmer does not exist!!&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;pom.xml&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&amp;lt;dependency&amp;gt;&lt;br /&gt;     &amp;lt;groupId&amp;gt;org.springframework&amp;lt;/groupId&amp;gt;&lt;br /&gt;     &amp;lt;artifactId&amp;gt;spring-webmvc&amp;lt;/artifactId&amp;gt;&lt;br /&gt;     &amp;lt;version&amp;gt;2.5&amp;lt;/version&amp;gt;      &lt;br /&gt; &amp;lt;/dependency&amp;gt;     &lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;web.xml&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="ISO-8859-1"?&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.&lt;br /&gt;com/dtd/web-app_2_3.dtd"&amp;gt;&lt;br /&gt;&amp;lt;web-app&amp;gt;&lt;br /&gt; &amp;lt;display-name&amp;gt;rest-webapp&amp;lt;/display-name&amp;gt;&lt;br /&gt; &amp;lt;description&amp;gt;Test Rest Service&amp;lt;/description&amp;gt;&lt;br /&gt; &amp;lt;servlet&amp;gt;&lt;br /&gt;  &amp;lt;servlet-name&amp;gt;mytest&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;  &amp;lt;servlet-class&amp;gt;org.springframework.web.servlet.DispatcherServlet&amp;lt;/servlet-class&amp;gt;&lt;br /&gt;  &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;lt;servlet-name&amp;gt;mytest&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;  &amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt; &amp;lt;/servlet-mapping&amp;gt;&lt;br /&gt; &amp;lt;session-config&amp;gt;&lt;br /&gt;  &amp;lt;session-timeout&amp;gt;1&amp;lt;/session-timeout&amp;gt;&lt;br /&gt; &amp;lt;/session-config&amp;gt;&lt;br /&gt;&amp;lt;/web-app&amp;gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-size:130%;"&gt;mytest-servlet.xml (Spring Application Context)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"&amp;gt;&lt;br /&gt;&amp;lt;beans&amp;gt;&lt;br /&gt;  &lt;br /&gt; &amp;lt;bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&amp;gt;&lt;br /&gt;  &amp;lt;property name="mappings"&amp;gt;&lt;br /&gt;   &amp;lt;props&amp;gt;&lt;br /&gt;    &amp;lt;prop key="/evil/programmers/*"&amp;gt;myController&amp;lt;/prop&amp;gt;    &lt;br /&gt;   &amp;lt;/props&amp;gt;&lt;br /&gt;  &amp;lt;/property&amp;gt;&lt;br /&gt; &amp;lt;/bean&amp;gt;&lt;br /&gt;  &lt;br /&gt; &amp;lt;bean id="myController" class="au.bandaid.programming.controller.MyTestController"&amp;gt;  &lt;br /&gt; &amp;lt;/bean&amp;gt;  &lt;br /&gt; &lt;br /&gt;&amp;lt;/beans&amp;gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;MyTestController.java&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;package au.bandaid.programming.controller;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;import java.io.IOException;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;import java.io.PrintWriter;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;import java.util.Hashtable;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;import java.util.regex.Matcher;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;import java.util.regex.Pattern;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;import javax.servlet.http.HttpServletRequest;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;import javax.servlet.http.HttpServletResponse;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;import org.springframework.web.servlet.ModelAndView;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;import org.springframework.web.servlet.mvc.Controller;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;import au.bandaid.programming.exception.HttpStatusException;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;public class MyTestController implements Controller {            &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    private Hashtable&lt;string,string&gt; list;&lt;/string,string&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    public MyTestController() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        list = new Hashtable&lt;string,string&gt;();&lt;/string,string&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        // Set an arbitary list&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        list.put("1", "Dr Evil");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        list.put("2", "Big Bad Billy");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        list.put("3", "Big Bad Billy");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        list.put("4", "Stevie Exception");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        list.put("4", "Frank Void");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;                                        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        // Determine the type of method&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        try {                        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            if (request.getMethod().toUpperCase().equals("GET")) {            &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;                writeResponse(response, "text/xml", HttpServletResponse.SC_OK, get(request));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            }            &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            //else if (method.toUpperCase().equals("POST"))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            //else if (method.toUpperCase().equals("DELETE"))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            //else if (method.toUpperCase().equals("PUT"))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;                    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            else {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;                throw new HttpStatusException(HttpServletResponse.SC_NOT_IMPLEMENTED, "Operation: " + request.getMethod() + " not supported.");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            }            &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        catch (HttpStatusException e) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            response.sendError(e.getStatusCode(), e.getMessage());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        catch (Exception e) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;                        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        return null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    }    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    private String get(HttpServletRequest request) throws HttpStatusException {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        // Grab some parameters&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        // I am not using any now&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        String type = request.getParameter("type");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        // Look at the request&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        // am expecting rest-webapp/programmers/1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        Pattern p = Pattern.compile("[1-9]+");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        Matcher m = p.matcher(request.getPathInfo());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        String index = "";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        if (m.find()) {                    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            index = m.group();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        if (!list.containsKey(index)) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            throw new HttpStatusException(HttpServletResponse.SC_NOT_FOUND, "This evil programmer does not exist!!");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        return "&lt;response&gt;" + list.get(index) + "&lt;/response&gt;";        &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    }    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    private void writeResponse(HttpServletResponse response, String contentType, int statusCode, String ouput) throws IOException {    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        response.setContentType(contentType);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        response.setStatus(statusCode);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        PrintWriter out = new PrintWriter(response.getOutputStream());&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        out.println(ouput);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        out.close();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Some extra reading:&lt;br /&gt;http://jira.springframework.org/browse/SPR-4419 - Comprehensive REST Support&lt;br /&gt;http://springframework.org/docs/MVC-step-by-step/Spring-MVC-step-by-step.html&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-5425178413484300767?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/5425178413484300767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=5425178413484300767' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/5425178413484300767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/5425178413484300767'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2008/05/rest-in-spring-without-using-spring.html' title='REST in Spring without using Spring Webservices'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-1816440781213547344</id><published>2008-04-29T10:32:00.000+10:00</published><updated>2008-08-11T23:07:03.949+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Style'/><title type='text'>Some have style, unfortunately most don't</title><content type='html'>Last year I came across this post by Kathy Sierra entitled &lt;a href="http://headrush.typepad.com/creating_passionate_users/2006/03/code_like_a_gir.html"&gt;Code Like a Girl&lt;/a&gt;. (It's a great little article and I even wanted to get a t-shirt made up saying - Do you code like a girl?) Since then I have been pondering the issue of writing code that not only works, but looks good and is ultimately understandable to the developer who will come after me to maintain it.&lt;br /&gt;&lt;br /&gt;Over the past year I have done a fair bit of maintenance on a legacy app. One thing that struck me is that the app has had a number of developers over the years. Each developer has stamped his/her  mark on it.  In some cases the stamp is great and in other cases what they have done is rather average. I also noticed a distinct lack of consistency in variable/class names, documentation etc. My job has been to fix a few defects or add some functionality. Typically taking days to understand how the code works and then making 5-10 lines of changes. In each case I have been tempted to redo, rewrite or refactor the code into my style. (I suspect most developers are often tempted with these dark thoughts). But then I faced the risk of breaking something or stamping yet another developers fancy onto the every-growing mangled mess of code. (A side issue is that I see coding as a form of art - maybe a later blog).&lt;br /&gt;&lt;br /&gt;Recently I saw this oldish book at work &lt;a href="http://www.amazon.com/Elements-Java-Style-Allan-Vermeulen/dp/0521777682/ref=pd_bbs_sr_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1209430203&amp;amp;sr=8-1"&gt;The Elements of Java Style&lt;/a&gt;. Nothing too earth shattering in the book but I just loved these principles:&lt;br /&gt;&lt;ul style="font-style: italic;"&gt;&lt;li&gt;Adhere to the style of the original&lt;/li&gt;&lt;li&gt;Adhere to the Principle of Least Astonishment - avoid doing things that will surprise the user of your code (If I had a dollar for every time I have been astounded by someone's "creativity" ...)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Document any deviations&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;In the first chapter it states:&lt;br /&gt;&lt;span style="font-style: italic;"&gt;"All good software performs well. But great software, written with style, is predictable, robust, maintainable, supportable, and extensible."&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;There are plenty of style guides out there. But in my experience developers just don't do it. Just imagine if we did. Wouldn't it be cool?&lt;span style="font-style: italic;"&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/8709325616717239681-1816440781213547344?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/1816440781213547344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=1816440781213547344' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/1816440781213547344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/1816440781213547344'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2008/04/some-have-style-unfortunately-most-dont.html' title='Some have style, unfortunately most don&apos;t'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-3248378027883569822</id><published>2008-03-25T11:50:00.000+11:00</published><updated>2008-08-13T20:50:27.450+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='tomcat'/><category scheme='http://www.blogger.com/atom/ns#' term='maven'/><title type='text'>Maven Webapps debug with Eclipse and Tomcat</title><content type='html'>I like using Maven. I also like using Step-Trace-Debugging. So here is what I do to accomplish this using Tomcat, Maven and Eclipse.&lt;br /&gt;&lt;br /&gt;Required:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Eclipse Sysdeo Tomcat Plugin &lt;a href="http://www.eclipseplugincentral.com/Web_Links-index-req-viewlink-cid-120.html"&gt;&lt;span class="nobr"&gt;&lt;/span&gt;&lt;/a&gt;&lt;a title="Visit page outside Confluence" rel="nofollow"&gt;http://www.eclipseplugincentral.com/Web_Links-index-req-viewlink-cid-120.html&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;span class="nobr"&gt;Eclipse Maven Plugin&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;Steps:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Create or Import your maven project into Eclipse&lt;/li&gt;&lt;li&gt;Select File &gt; Properties for this project&lt;/li&gt;&lt;li&gt;Select the Tomcat property&lt;/li&gt;&lt;li&gt;Check the box "Is a Tomcat Project"&lt;/li&gt;&lt;li&gt;Enter the context name. For my example, dcmdb&lt;/li&gt;&lt;li&gt;Click Apply&lt;/li&gt;&lt;li&gt;Go to &lt;tomcat_home&gt;/conf/Catalina/localhost and edit the context file i.e. dcmdb.xml.  &lt;/tomcat_home&gt;&lt;ul&gt;&lt;li&gt;Edit the docBase and workDir to point to the location of your maven project&lt;/li&gt;&lt;li&gt;Notice that the docbase &lt;b&gt;should point to ../dcmdb/target/dcmdb-1.0&lt;/b&gt; where   &lt;ul&gt;&lt;li&gt;&lt;b&gt;../dcmdb&lt;/b&gt; = the location of my maven project&lt;/li&gt;&lt;li&gt;../target/ = the directory that is created when using the maven package command&lt;/li&gt;&lt;li&gt;../dcmdcb-1.0 = the directory that is my artifact name. It's the webapp&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;The final step involves changing the Java Build Path property in Eclipse by pointing the source output to &lt;maven&gt;/target&lt;artifact&gt;/dcmdb-1.0/WEB-INF/classes. This means that once you make a change to your code all you need to do is restart tomcat.  &lt;/artifact&gt;&lt;/maven&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/8709325616717239681-3248378027883569822?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/3248378027883569822/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=3248378027883569822' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/3248378027883569822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/3248378027883569822'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2008/03/maven-webapps-debug-with-eclipse-and.html' title='Maven Webapps debug with Eclipse and Tomcat'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-3933720998603429611</id><published>2008-03-08T15:09:00.000+11:00</published><updated>2008-08-11T23:10:04.271+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='rails'/><title type='text'>Learning Ruby on Rails 2.0</title><content type='html'>I have finally made some time to start learning Ruby on Rails. Here's my story:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Downloading and installing&lt;/span&gt;&lt;br /&gt;Well at home I am running windows on a laptop with busted keys. Because one of my offspring keeps ripping keys from the keyboard. The latest victims are the spacebar and the "n" key. Sad but true. So I am a little lazy at times I so installed instant rails: &lt;a href="http://instantrails.rubyforge.org/wiki/wiki.pl"&gt;http://instantrails.rubyforge.org/wiki/wiki.pl&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Finding a  suitable tutorial&lt;/span&gt;&lt;br /&gt;I then discovered that there is a difference between Rails 2.0 and 1.x. But Rails 2.0 tutorials seem hard to come by (well again if Google does not produce on the first page ... then it's hard to find :)&lt;br /&gt;&lt;br /&gt;Ones that I did find and am working through:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://fairleads.blogspot.com/2007/12/rails-20-and-scaffolding-step-by-step.html"&gt;http://fairleads.blogspot.com/2007/12/rails-20-and-scaffolding-step-by-step.html&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial"&gt;http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;Will update as I go.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-3933720998603429611?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/3933720998603429611/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=3933720998603429611' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/3933720998603429611'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/3933720998603429611'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2008/03/learning-ruby-on-rails-20.html' title='Learning Ruby on Rails 2.0'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-2477759797601830534</id><published>2007-11-09T09:50:00.000+11:00</published><updated>2008-08-11T23:07:37.681+10:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Agile'/><title type='text'>The fluff on Stand-up Meetings</title><content type='html'>Haven't done any standup meetings yet. But read "&lt;a href="http://martinfowler.com/articles/itsNotJustStandingUp.html"&gt;It's not just standing up: Patterns of daily stand-up meetings.&lt;/a&gt;" by Jason Yip.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-2477759797601830534?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/2477759797601830534/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=2477759797601830534' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/2477759797601830534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/2477759797601830534'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2007/11/fluff-on-stand-up-meetings.html' title='The fluff on Stand-up Meetings'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8709325616717239681.post-8328439881689115597</id><published>2007-06-28T10:28:00.001+10:00</published><updated>2009-09-04T16:19:07.804+10:00</updated><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='Spring'/><title type='text'>The Hans Gruber effect - Using Spring and Hibernate JPA</title><content type='html'>At the end of the movie &lt;a href="http://en.wikipedia.org/wiki/Die_Hard"&gt;Die Hard&lt;/a&gt; John McClane (Bruce Willis), releases the watch from Holly's wrist which results in Hans Gruber (Alan Rickman) falling to his death. Hans was hanging out of a window in a huge high rise, holding onto the wrist of Holly. The iconic scene has the view from their perpective seeing Hans flapping his arms moving further and further away from them as he falls to the ground. In some ways I felt like Hans flapping my arms trying to make Hibernate JPA and Spring work, whilst gravity was pulling me closer to my death ...&lt;br /&gt;&lt;br /&gt;Well my work colleague, &lt;a href="http://aons2dev.blogspot.com/"&gt;Dave&lt;/a&gt;, first put me on the path to enlightenment. He references &lt;a href="http://icoloma.blogspot.com/2006/11/jpa-and-spring-fucking-cooltm_26.html"&gt;Ignacio's&lt;/a&gt; experience or rather what he did to make the thing work. However, in all the references I flapped more and more as they all do it a little differently. Also Ignacio uses Spring auto-wiring and recently in a Spring course by Interface 21, the presenter, reckoned that auto-wiring should not really be used.&lt;br /&gt;&lt;br /&gt;Maybe the biggest factor in my Hans Gruber impersonation is that at times everyone else makes it look so easy while I feel like a dufus. But I did eventually succeed.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Here's how it worked for me:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I pretty much based everything I did on Getting Started with JPA in Spring 2.0, however I couldn't get it to work properly. I also used Hibernate JPA and therefore had to make a few changes. I will list these changes below.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Issue 1: Gather all the required Jar's&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is a bit of a problem as many of the blogs I read didn't give a list of Jar's required. I downloaded a version of:&lt;br /&gt;&lt;br /&gt;* Spring 2.04&lt;br /&gt;* Hibernate 3.2&lt;br /&gt;* Hibernate Entity Manager 3.3.1&lt;br /&gt;&lt;br /&gt;From these downloads a I used the following jar files. Still not sure if they are all needed but here is the list:&lt;br /&gt;&lt;br /&gt;antlr-2.7.6.jar&lt;br /&gt;dom4j-1.6.1.jar&lt;br /&gt;javassist.jar&lt;br /&gt;asm-attrs.jar&lt;br /&gt;ejb3-persistence.jar&lt;br /&gt;jboss-archive-browsing.jar&lt;br /&gt;asm.jar&lt;br /&gt;hibernate-annotations.jar&lt;br /&gt;jta.jar&lt;br /&gt;cglib-2.1.3.jar&lt;br /&gt;hibernate-commons-annotations.jar&lt;br /&gt;log4j-1.2.14.jar&lt;br /&gt;classes12.jar (I am using Oracle DB)&lt;br /&gt;hibernate-entitymanager.jar&lt;br /&gt;spring-2.0.4.jar&lt;br /&gt;commons-collections-2.1.1.jar&lt;br /&gt;hibernate-validator.jar&lt;br /&gt;commons-logging-1.0.4.jar&lt;br /&gt;hibernate3.jar&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Issue 2: Spring config file&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There were a few issues with setting up the config file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Note the following:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Include the annotations for transactions, this becomes relevant when performing transactions and a solution for Lazy fetches.&lt;/li&gt;&lt;li&gt;I couldn't get it to wotk with ContainerEntityManagerFactoryBean so I used LocalContainerEntityManagerFactoryBean&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;beans xmlns="http://www.springframework.org/schema/beans"&lt;br /&gt;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" &lt;br /&gt;xmlns:tx="http://www.springframework.org/schema/tx"&lt;br /&gt;xsi:schemaLocation="&lt;br /&gt;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&lt;br /&gt;http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;!-- Put this here if you want to use transactions --&amp;gt;&lt;br /&gt;&amp;lt;tx:annotation-driven transaction-manager="transactionManager"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;!-- This comes from the blog&lt;br /&gt;http://blog.interface21.com/main/2006/05/30/getting-started-with-jpa-in-spring-20/ --&amp;gt;&lt;br /&gt;&amp;lt;bean id="restaurantDao" class="blog.jpa.dao.JpaRestaurantDao"&amp;gt;&lt;br /&gt;&amp;lt;property name="entityManagerFactory" ref="entityManagerFactory"/&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;!-- I used Oracle just change the dialect below to match your db --&amp;gt;&lt;br /&gt;&amp;lt;!-- I couldn't get the ContainerEntityManagerFactoryBean to work&lt;br /&gt;so I used LocalContainerEntityManagerFactoryBean --&amp;gt;&lt;br /&gt;&amp;lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&amp;gt;&lt;br /&gt;&amp;lt;property name="dataSource" ref="dataSource" /&amp;gt;&lt;br /&gt;&amp;lt;property name="jpaVendorAdapter"&amp;gt;&lt;br /&gt;&amp;lt;bean&lt;br /&gt;class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&amp;gt;&lt;br /&gt;&amp;lt;property name="showSql" value="true" /&amp;gt;&lt;br /&gt;&amp;lt;property name="generateDdl" value="false" /&amp;gt;&lt;br /&gt;&amp;lt;property name="databasePlatform" value="org.hibernate.dialect.Oracle9Dialect" /&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&amp;gt;&lt;br /&gt;&amp;lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /&amp;gt;&lt;br /&gt;&amp;lt;property name="url" value="jdbc:oracle:thin:@xxx:1521:xxx" /&amp;gt;&lt;br /&gt;&amp;lt;property name="username" value="bandaid" /&amp;gt;&lt;br /&gt;&amp;lt;property name="password" value="bandaid" /&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&amp;gt;&lt;br /&gt;&amp;lt;property name="entityManagerFactory" ref="entityManagerFactory" /&amp;gt;&lt;br /&gt;&amp;lt;property name="dataSource" ref="dataSource" /&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/beans&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Issue 3: Lazy vs Eager Fetching&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;All was happy until I started playing around with lazy fetching. The problem was that I kept getting a session ending error after the initial read. This appears to be a Spring issue. Spring closes the database connection and you try to do the lazy fetch it throws an error that basically means the database connection doe snot exist. So after reading many blogs, pulling my hair out and crying myself to sleep at night, I stumbled onto the following blog Hibernate Lazy Loading.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;I discovered a few work arounds for Spring:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Don't make any Lazy calls and just call the collection manually. I didn't like that option.&lt;/li&gt;&lt;li&gt;Make everything Eager. Not a good one either.&lt;/li&gt;&lt;li&gt;Implement the OpenSessionInViewFilter in the Spring config. I read a few more blogs, referenced all the spring books I had and still couldn't get the thing to work. It does seem to work but I couldn't figure it out.&lt;/li&gt;&lt;li&gt;Use the Spring @Transaction annotation for the method or class. That's why I declared the annotations in the above spring config file.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Outcome&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I am very happy. Smiles all round. After many days impersonating Hans Gruber, I finally got the thing to work. It's really simple and easy. I will tell my friends about it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8709325616717239681-8328439881689115597?l=bandaidprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bandaidprogramming.blogspot.com/feeds/8328439881689115597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8709325616717239681&amp;postID=8328439881689115597' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/8328439881689115597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8709325616717239681/posts/default/8328439881689115597'/><link rel='alternate' type='text/html' href='http://bandaidprogramming.blogspot.com/2007/06/at-end-of-movie-die-hard-john-mcclane.html' title='The Hans Gruber effect - Using Spring and Hibernate JPA'/><author><name>Tez</name><uri>http://www.blogger.com/profile/13063416812031779283</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://bp0.blogger.com/_y_3D2KrTQQo/R9IWLpzOh1I/AAAAAAAAAAM/fcidWGKPbfU/S220/tez.jpg'/></author><thr:total>3</thr:total></entry></feed>
