23 February 2009

Exceptions In Java [Must Read]

Exceptions were a big improvement over the old-fashioned C way of returning error codes, but then the debate raged over Checked vs Unchecked Exceptions, vs "Huh? Checked? Whazza?". Java offers all three varieties so you can never hope to port exceptional experience from one project to the next, because there are at least as many correct ways to do things as there are gurus. However, at least now there's a step in the right direction; with Björn Andersson's Java Exception Explanator a lot more of this makes sense. Check it out. Here's a teaser:

AccessControlException : You have lost control of Microsoft Access. If you cannot regain control or stop the program in some other way, you should cut the power to your computer as fast as possible.

ps. thanks reddit

Don't Forget To Flush

So, instead of being asleep like an honest citizen at 2 o'clock in the morning, here I am trying to make hibernate save my collection of Strings.

(I would hate not to be a developer: who else deals with Collections of Strings, I wonder?)

The mapping is perfect, straight from the documentation, to tricky stuff, no funny cases:

    <set name="categories" table="resources_categories">
      <key column="resource"/>
      <element column="category" type="string"/>

Except, when I populate my category list, and try getSession().save(newResource) ... it doesn't save my Strings!

After a little more googling than I would have hoped, I bumped into this - http://forum.hibernate.org/viewtopic.php?t=951848&blah blah... where the hibernate team says you have to flush in this case. You don't have to flush to save most other things, but if it's a Collection of Strings, you have to flush.

So this works:


- no changes to the mapping required.

22 February 2009

Another Smug Mac User

Today I got even smugger, if you can believe that. To cut a long, long story short, Sabrina, my beloved, a victim user of Windows Vista, was getting "Local Access Only" while connected to our trusty router that has always worked before, in our heterogeneous network of Mac, Ubuntu, and Various Windowses. The solution, in the end, was simple: "ipconfig /release" followed by "ipconfig /renew"*, but the path was labyrinthine. Innumerable fora record the despair and frustration of countless vista users facing the dreaded "Local Access Only" message

At the risk of repeating myself: the Mac is the first computer I've had that Mostly Just Works. The biggest annoyance with this thing is the no delete key - but there is a partial solution - KeyRemap4MacBook

But Vista? How can they break DHCP - something that's been working for over twelve years? How do people who are not technical deal with this?

(*) In case you came to this post in despair and frustration: here's how to run ipconfig

  1. Hit Start -> Run
  2. Enter "cmd" and hit return. A "command prompt" window will appear
  3. type "ipconfig /release" and hit return - this should get rid of any out-of-date connection state
  4. type "ipconfig /renew" and hit return - this gets you new connection state
  5. close the "cmd" window
Theoretically, and with a bit of luck, and assuming nothing else is wrong, and possibly after a slight delay, you'll have your internet again