Monday, August 27, 2007

ActiveHibernate follow-up

Not much happened the last couple of weeks because it was our summer vacation (which summer?). I have cleaned up the existing code a bit, and now I'm working on a Ruby way for Hibernate inheritance mapping.

Wednesday, August 15, 2007

Towards a mapping DSL for AH

Last week Ola Bini sent me a patch that showed a Hibernate mapping written inside the Ruby class definition, instead of relying on hand-written XML files (the horror!), like so:

class Project
include Hibernate

with_table_name "PROJECTS" #optional

primary_key_accessor :id,:long,:PROJECT_ID
hattr_accessor :date,:timestamp,:START_DATE
#column name is optional
hattr_accessor :name,:string
hattr_accessor :complexity,:double
hattr_accessor :size,:long
hattr_accessor :on_time,:boolean

By including the Hibernate module (as opposed to inheriting from a framework base class), the Hibernate mapping is generated and configured automatically. Utility class methods (like "save" and"find") and accessor methods for the mapped properties are also added.

It's all in the file dsl_test.rb (see the link in the top right corner for the code repository). It is far from complete, but thanks to Ola I can start filling the gaps (like inheritance, relations, components, ...). Let me know what you think!

Monday, August 6, 2007

First ActiveHibernate code on Google Code

Because it's all talk until the code runs, I have finally imported my code into a Google Code project ( There is no formal release yet, so you'll have to use a Subversion client to get it (or just browse the repository online). There's a readme file that explains how to get the tests running.

All feedback is more than welcome, as I'm new to (J)Ruby. I'm also very interested in ideas for a Ruby-like interface to Hibernate. The first thing that should be done is replacing the hbm.xml mapping files by a kind of annotations or a DSL (inspired by Rails or GORM, the OR/M in Grails).