Hibernate Naming Strategies

Using Hibernate annotations with the default naming strategy leaves you with camelCasedColumnNames in your database schema.

Gavin King provided a good camelCase to underscore_separated naming strategy with org.hibernate.cfg.ImprovedNamingStrategy. The only glitch I found was in foreign key references. I’ve always seen the naming convention of ${tablename}_id, but ImprovedNamingStrategy just called the column the same name as any other field. That’s easily overridden in a subclass:

public class NewAndImprovedNamingStrategy extends ImprovedNamingStrategy {
    @Override
    public String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName) {
        String s = super.foreignKeyColumnName(propertyName, propertyEntityName, propertyTableName, referencedColumnName);
        return s.endsWith("_id") ? s : s + "_id";
    }
}

If you’re using Spring, wire it up to your SessionFactoryBean:

  <bean id="namingStrategy" class="...NewAndImprovedNamingStrategy"/>
  ...
  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="namingStrategy" ref="namingStrategy"/>
    ...

And you’ll be freed from doing boilerplate “name=” attributes in your domain POJOs.

Tunnelblick crash recovery

I’ve found that waking my mac from suspend in a different network than it went to sleep in can crash tunnelblick, or cause tunnelblick to try to spin up another openvpn instance, leaving the network wedged. The workaround is to invoke this in a terminal:

sudo killall -v openvpn

then relaunch tunnelblick.

If that doesn’t work, force-unloading the kernel extension does the trick:

sudo killall -v openvpn
sudo killall -v Tunnelblick
sudo kextunload -b foo.tun

then relaunch tunnelblick.

Photomatix HDR with single RAW images

We got to visit the Yosemite valley a couple weekends ago, and as I was gaping and smiling at all the grandeur, I tried RAW one more time.

When I got home, though, iPhoto’s conversion was disappointing:

I did some research and found Photomatix — and on the same RAW image, I couldn’t believe it was from the same input! It’s easy:

  1. Find the name of the RAW image (you can get the filename in iPhoto by hitting ⌘-i when the image is selected)
  2. File > Open File..., and type the name of the image into the search box. If you have a Canon camera, the file suffix will be .cr2
  3. click the “Details Enhancer” button:

HDR without a tripod! w00t!

DegradedArray event on /dev/md0:gronk

Due to an unscheduled powercycle on my linux server, I got a very troubling page from mdadm, the multi-disk administrator, saying it had marked one of the disks as failed.

This, presumably, was due to a flaky SATA controller that didn’t make /dev/sda available by the time the kernel was mounting /dev/md0, so software raid turned it off.

It was easy enough to get the drive back into play:

sudo mdadm /dev/md0 --add /dev/sda1

And easy enough to monitor progress:

mrm@gronk:~$ cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sda1[3] dm-2[1] dm-1[0]
580074880 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_]
 [====>................]
recovery = 22.0% (63875072/290037440)
finish=178.1min speed=21154K/sec