Monday, June 7, 2010

Apache CouchDB is cool



2-layers made possible!  DB <-> front end, bypass app layer thanks to JSON over HTTP (RESTful)

Thursday, June 3, 2010

Hibernate Indexed Collections works with CF ORM!

By default, ColdFusion would use <bag> when you use type="array" to map "one-to-many" fieldtype.

/** Parent.cfc */
component persistent="true"
{
  property name="id" fieldtype="id" generator="native";
  property name="children" type="array" fieldtype="one-to-many" inverse="true" cfc="child" cascade="all";
}

Add this parent.hbxml below and save it in the same folder as parent.cfc if you want to use Indexed Collections.  Hibernate will do all the bookkeeping behind the scene for you to preserve the order of the array by storing the order in the sortOrder column (int).  Cool eh?

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class entity-name="parent" lazy="true" name="cfc:com.test.parent" table="parent">
<id name="id" type="int">
<column name="id"/>
<generator class="native"/>
</id>

<—- rename ‘bag’ to ‘list’ -->
<list name="children" cascade="all">
<key column="parent_id"/>
<—- set base="1" to match CF array index (optional, default to 0) -->
<list-index column="sortOrder" base="1"/>
<one-to-many class="cfc:com.test.child"/>
</list>

</class>
</hibernate-mapping>



Didn’t know it’s this easy! :)