Friday, July 27, 2007

ActiveHibernate: time to package

Good news. Hibernate collection mapping is up and running. Well, one example that is: Hibernate's bag type now works with Ruby Array's, lazy loading included. To get started I've done a shameless copy/paste of the Hibernate code for the bag collection type. That went fairly easy because the Java class RubyArray implements the java.util.List interface. So now the mapping files look like



<hibernate-mapping>

<class table="BLOGS" lazy="false" entity-name="Blog">

<tuplizer entity-mode="dynamic-map"
class="activehibernate.RubyTuplizer"/>

<id name="id" column="BLOG_ID" type="long">
<generator class="identity"/>
</id>

<property name="title" type="string" />

<bag name="items"
collection-type="activehibernate.RubyArrayType">
<key column="blog_id" />
<one-to-many entity-name="Item"/>
</bag>

</class>

</hibernate-mapping>



where Blog and Item are genuine Ruby classes. The nice part is that I haven't touched any existing Hibernate or JRuby code.


The plan is to package the things I already have (still need to write more tests to show what is working) and put it on SourceForge or Google Code to get some feedback from JRuby and/or Hibernate people. (I can very well imagine I've made things to complex where simpler solutions exist out-of-the-box.) After that it's time to start looking at ways to get rid of the XML mapping files by writing a friendly Ruby interface around the Hibernate details.


I hope that after some time this project will be stable/useful enough to be part of JRuby Extras at RubyForge.

No comments: