ExtendedGormMappings Plugin

  • Tags: persistence
  • Latest: 0.4
  • Last Updated: 29 June 2010
  • Grails version: 1.3.2 > *
  • Authors: null
0 vote
compile ":extended-gorm-mappings:0.4"




Install the plugin with the command:
grails install-plugin extended-gorm-mappings



This plugin adds extra options to the mapping closure in GORM domain classes. It includes a few mappings with the plugin, but it also provides the infrastructure for you to easily add mapping extensions in your own code.

Built-in mappings

MappingData TypeDescription
insertablebooleancontrols whether this column is included in INSERT statements
updateablebooleancontrols whether this column is included in UPDATE statements
formulastringprovides a SQL formula to be used in SELECT statements instead of binding this field to a database column. Implicitly makes the column read-only
  Example: firstOrderDate formula: "(select min(o.creation_date) from Orders o where o.customer_id = id)"

Version history

0.3Insertable:false and Formula mappings now add a nullable:true constraint so you're not forced to enter a value you can't save. Formula mappings will no longer create a column if you're generating schema. Schema generation for Insertable:false mappings will no longer create columns as NOT NULL
0.2Upgraded for grails 1.1.x
0.1Initial release for grails 1.0.x

How it works

Grails builds a Configuration and then uses that Configuration to create a SessionFactory. This plugin extends grail's ConfigurableLocalSessionFactoryBean and modifies the hibernate Configuration just before the SessionFactory is built.

Creating your own mappings

Rather than hardcode a list of mapping extensions, this plugin queries the application context for any beans that implement the interface

package org.riskfactor.grails.gorm;

import org.hibernate.mapping.Property;

public interface GormExtension { void extend(GrailsDomainClass domainClass, Property prop, Object setting); String getKey(); }

When the plugin finds key in a domain object's mapping closure, it will pass the associated value as the setting argument to the extend method. The prop argument is the hibernate Property that grails has constructed to map the column. In your extend method, you modify this property. You'll need some familiarity with the org.hibernate.mapping package to make this work, but you can look at the included GormExtensions for examples.